Skip to content

Commit

Permalink
Auction Module Unit Tests (#180)
Browse files Browse the repository at this point in the history
* Add in base test auction keeper with mocked expected keepers

* Fix bug in keystore lookup & do happy path for BeginAuction

* Minor bug fix and happy path for finishing auction

* lint

* test

* Msg server happy path unit test

* Partial implementation for abci test

* Abci unit test happy path

* Partially fulfilled bid test

* Partial unhappy path for msg server

* Finish unhappy path tests for msg server

* Make linter happy

* Finish unhappy paths for keeper, msg server, & abci

* Add genesis unit testing and fix up genesis import + add validate basic ccheck to token price setting

* Proposal handler unit testing

* Query server tests

* Add auction types validation testing and remove some unnecessary errors

* Genesis validate test

* Add in msg validation test

* Add params validate test

* Proposal validation test

* Cli query tests

* Tx unit tests

* Add auction module account keeper

* Added mock account keeper

* Partial unit test update to account for new expected keeper

* Update unit tests to account for latest updates in integration test sister PR

* lint

* Tidy

* Partial address of comments

* More feedback being addressed

* Unit test workflow

* Address review comments
  • Loading branch information
philipjames44 authored Nov 3, 2022
1 parent 1b305e6 commit fd56a1f
Show file tree
Hide file tree
Showing 34 changed files with 3,585 additions and 185 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Unit tests

on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:

jobs:
test:
strategy:
matrix:
go-version: [1.16]
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- run: go test github.com/peggyjv/sommelier/.../x/...
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func NewSommelierApp(

app.AuctionKeeper = auctionkeeper.NewKeeper(
appCodec, keys[auctiontypes.StoreKey], app.GetSubspace(auctiontypes.ModuleName),
app.BankKeeper, map[string]bool{cellarfeestypes.ModuleName: true},
app.BankKeeper, app.AccountKeeper, map[string]bool{cellarfeestypes.ModuleName: true},
map[string]bool{cellarfeestypes.ModuleName: true},
)

Expand Down Expand Up @@ -445,7 +445,7 @@ func NewSommelierApp(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
cork.NewAppModule(app.CorkKeeper, appCodec),
cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper),
auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, appCodec),
auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, app.AccountKeeper, appCodec),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -506,7 +506,7 @@ func NewSommelierApp(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
cork.NewAppModule(app.CorkKeeper, appCodec),
cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper),
auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, appCodec),
auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, app.AccountKeeper, appCodec),
)

app.sm.RegisterStoreDecoders()
Expand Down
3 changes: 1 addition & 2 deletions proto/auction/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ service Msg {

message MsgSubmitBidRequest {
uint32 auction_id = 1;
string bidder = 2;
string signer = 2;
cosmos.base.v1beta1.Coin max_bid_in_usomm = 3 [ (gogoproto.nullable) = false ];
cosmos.base.v1beta1.Coin sale_token_minimum_amount = 4 [ (gogoproto.nullable) = false ];
string signer = 5;
}

message MsgSubmitBidResponse {
Expand Down
45 changes: 45 additions & 0 deletions testutil/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

// TODO(pbal): This is copied from an unreleased version of the cosmos sdk. Upon upgrading our sdk version to 0.46.1 we should import this file

// TestEncodingConfig defines an encoding configuration that is used for testing
// purposes. Note, MakeTestEncodingConfig takes a series of AppModuleBasic types
// which should only contain the relevant module being tested and any potential
// dependencies.
type TestEncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig {
cdc := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
codec := codec.NewProtoCodec(interfaceRegistry)

encCfg := TestEncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes),
Amino: cdc,
}

mb := module.NewBasicManager(modules...)

std.RegisterLegacyAminoCodec(encCfg.Amino)
std.RegisterInterfaces(encCfg.InterfaceRegistry)
mb.RegisterLegacyAminoCodec(encCfg.Amino)
mb.RegisterInterfaces(encCfg.InterfaceRegistry)

return encCfg
}
Loading

0 comments on commit fd56a1f

Please sign in to comment.