Skip to content

Commit

Permalink
Fix GetDepositSudoMsg (sei-protocol#684)
Browse files Browse the repository at this point in the history
* Fix GetDepositSudoMsg

* fix test
  • Loading branch information
codchen authored Apr 3, 2023
1 parent 813cc83 commit 4f02a86
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ require (
replace (
github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.0.1
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.13
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.14
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.3
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,8 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921/go.mod
github.com/securego/gosec/v2 v2.11.0 h1:+PDkpzR41OI2jrw1q6AdXZCbsNGNGT7pQjal0H0cArI=
github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sei-protocol/sei-cosmos v0.2.13 h1:legDUxrbj+hfGbXFk0ivziO8NfwmP9GkER9yqOL0VOw=
github.com/sei-protocol/sei-cosmos v0.2.13/go.mod h1:CYMdG9mBiQ9Dfw3Wd+JCF+ph7NpySllMAnMA3qNG5ro=
github.com/sei-protocol/sei-cosmos v0.2.14 h1:UHdTI9QKI02VFlnBCyAUsOQQlBuNH3p70TGUW6qr5aQ=
github.com/sei-protocol/sei-cosmos v0.2.14/go.mod h1:CYMdG9mBiQ9Dfw3Wd+JCF+ph7NpySllMAnMA3qNG5ro=
github.com/sei-protocol/sei-iavl v0.1.3 h1:0hvW1NtmBlZ7ZkerQcM/n+2tFKg0vUlYWK8q/OeuCgw=
github.com/sei-protocol/sei-iavl v0.1.3/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk=
github.com/sei-protocol/sei-tendermint v0.2.2 h1:lwzqgMIF8XyLE7r3VGRv0t6nLxLLDmoOUDcnKw+whNE=
Expand Down
2 changes: 1 addition & 1 deletion x/dex/keeper/abci/end_block_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (w KeeperWrapper) GetDepositSudoMsg(ctx sdk.Context, typedContractAddr type
)
escrowed := sdk.NewCoins()
for _, deposit := range depositMemState {
escrowed.Add(sdk.NewCoin(deposit.Denom, deposit.Amount.TruncateInt()))
escrowed = escrowed.Add(sdk.NewCoin(deposit.Denom, deposit.Amount.TruncateInt()))
}
contractAddr, err := sdk.AccAddressFromBech32(string(typedContractAddr))
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions x/dex/keeper/abci/end_block_place_orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
dexcache "github.com/sei-protocol/sei-chain/x/dex/cache"
"github.com/sei-protocol/sei-chain/x/dex/keeper/abci"
"github.com/sei-protocol/sei-chain/x/dex/types"
dextypes "github.com/sei-protocol/sei-chain/x/dex/types"
typesutils "github.com/sei-protocol/sei-chain/x/dex/types/utils"
dexutils "github.com/sei-protocol/sei-chain/x/dex/utils"
minttypes "github.com/sei-protocol/sei-chain/x/mint/types"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
Expand Down Expand Up @@ -41,6 +43,13 @@ func TestGetDepositSudoMsg(t *testing.T) {
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.StoreKey))))
testAccount, _ := sdk.AccAddressFromBech32("sei1yezq49upxhunjjhudql2fnj5dgvcwjj87pn2wx")
amounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(1000000)))
bankkeeper := testApp.BankKeeper
bankkeeper.MintCoins(ctx, minttypes.ModuleName, amounts)
err := bankkeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, testAccount, amounts)
require.Nil(t, err)
// this send would happen in msg server
err = bankkeeper.SendCoinsFromAccountToModule(ctx, testAccount, dextypes.ModuleName, amounts)
require.Nil(t, err)
keeper := testApp.DexKeeper
dexutils.GetMemState(ctx.Context()).GetDepositInfo(ctx, keepertest.TestContract).Add(
&types.DepositInfoEntry{
Expand All @@ -52,4 +61,8 @@ func TestGetDepositSudoMsg(t *testing.T) {
wrapper := abci.KeeperWrapper{Keeper: &keeper}
msgs := wrapper.GetDepositSudoMsg(ctx, keepertest.TestContract)
require.Equal(t, 1, len(msgs.OrderPlacements.Deposits))

contractAddr, _ := sdk.AccAddressFromBech32(keepertest.TestContract)
contractBalance := testApp.BankKeeper.GetBalance(ctx, contractAddr, "usei")
require.Equal(t, contractBalance.Amount.Int64(), int64(1000000))
}
10 changes: 10 additions & 0 deletions x/dex/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func TestEndBlockMarketOrder(t *testing.T) {
bankkeeper := testApp.BankKeeper
bankkeeper.MintCoins(ctx, minttypes.ModuleName, amounts)
bankkeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, testAccount, amounts)
dexAmounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(5000000)), sdk.NewCoin("uusdc", sdk.NewInt(10000000)))
bankkeeper.SendCoinsFromAccountToModule(ctx, testAccount, types.ModuleName, dexAmounts)
wasm, err := ioutil.ReadFile("./testdata/mars.wasm")
if err != nil {
panic(err)
Expand Down Expand Up @@ -187,6 +189,8 @@ func TestEndBlockLimitOrder(t *testing.T) {
bankkeeper := testApp.BankKeeper
bankkeeper.MintCoins(ctx, minttypes.ModuleName, amounts)
bankkeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, testAccount, amounts)
dexAmounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(5000000)), sdk.NewCoin("uusdc", sdk.NewInt(10000000)))
bankkeeper.SendCoinsFromAccountToModule(ctx, testAccount, types.ModuleName, dexAmounts)
wasm, err := ioutil.ReadFile("./testdata/mars.wasm")
if err != nil {
panic(err)
Expand Down Expand Up @@ -402,6 +406,8 @@ func TestEndBlockPartialRollback(t *testing.T) {
bankkeeper := testApp.BankKeeper
bankkeeper.MintCoins(ctx, minttypes.ModuleName, amounts)
bankkeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, testAccount, amounts)
dexAmounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(500000)), sdk.NewCoin("uusdc", sdk.NewInt(1000000)))
bankkeeper.SendCoinsFromAccountToModule(ctx, testAccount, types.ModuleName, dexAmounts)
wasm, err := ioutil.ReadFile("./testdata/mars.wasm")
if err != nil {
panic(err)
Expand Down Expand Up @@ -502,6 +508,8 @@ func TestEndBlockPanicHandling(t *testing.T) {
bankkeeper := testApp.BankKeeper
bankkeeper.MintCoins(ctx, minttypes.ModuleName, amounts)
bankkeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, testAccount, amounts)
dexAmounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(5000000)))
bankkeeper.SendCoinsFromAccountToModule(ctx, testAccount, types.ModuleName, dexAmounts)
wasm, err := ioutil.ReadFile("./testdata/mars.wasm")
if err != nil {
panic(err)
Expand Down Expand Up @@ -559,6 +567,8 @@ func TestEndBlockRollbackWithRentCharge(t *testing.T) {
bankkeeper := testApp.BankKeeper
bankkeeper.MintCoins(ctx, minttypes.ModuleName, amounts)
bankkeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, testAccount, amounts)
dexAmounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(500000)), sdk.NewCoin("uusdc", sdk.NewInt(1000000)))
bankkeeper.SendCoinsFromAccountToModule(ctx, testAccount, types.ModuleName, dexAmounts)
wasm, err := ioutil.ReadFile("./testdata/mars.wasm")
if err != nil {
panic(err)
Expand Down

0 comments on commit 4f02a86

Please sign in to comment.