Skip to content

Commit

Permalink
fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Mar 12, 2024
1 parent de029a4 commit 7663195
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app_test

import (
"encoding/json"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -692,6 +693,13 @@ func (s *AppGenesisTestSuite) TestGenesis() {
"params": {
},
"settings": [
{
"owner": "terra1tck9vx8vwu6l83zy76ssdkhnhw8dfcrt80hc6x",
"authorization": [],
"pre_transaction": [],
"post_transaction": [],
"fallback": true
}
]
},
"staking": {
Expand Down Expand Up @@ -752,5 +760,7 @@ func (s *AppGenesisTestSuite) TestGenesis() {
"sequences": []
}
}`
// write jsonGenState to file for debugging
ioutil.WriteFile("genesis1.json", jsonGenState, 0644)
s.Require().JSONEq(string(jsonGenState), expectedState)
}
30 changes: 25 additions & 5 deletions x/smartaccount/ante/tests/pretransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,39 @@ func (s *AnteTestSuite) TestPreTransactionHookWithoutSmartAccount() {

func (s *AnteTestSuite) TestPreTransactionHookWithEmptySmartAccount() {
s.Setup()

// set settings
err := s.SmartAccountKeeper.SetSetting(s.Ctx, smartaccounttypes.Setting{
Owner: s.TestAccs[0].String(),
})
require.NoError(s.T(), err)

s.Ctx = s.Ctx.WithValue(smartaccounttypes.ModuleName, smartaccounttypes.Setting{})
txBuilder := s.BuildDefaultMsgTx(0, &types.MsgSend{
FromAddress: s.TestAccs[0].String(),
ToAddress: s.TestAccs[1].String(),
Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 100000000)),
})
_, err := s.PreTxDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{}))
_, err = s.PreTxDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{}))
require.NoError(s.T(), err)
}

func (s *AnteTestSuite) TestInvalidContractAddress() {
s.Setup()
s.Ctx = s.Ctx.WithValue(smartaccounttypes.ModuleName, smartaccounttypes.Setting{

// set settings
err := s.SmartAccountKeeper.SetSetting(s.Ctx, smartaccounttypes.Setting{
Owner: s.TestAccs[0].String(),
PreTransaction: []string{s.TestAccs[0].String()},
})
require.NoError(s.T(), err)

txBuilder := s.BuildDefaultMsgTx(0, &types.MsgSend{
FromAddress: s.TestAccs[0].String(),
ToAddress: s.TestAccs[1].String(),
Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 100000000)),
})
_, err := s.PreTxDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{}))
_, err = s.PreTxDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{}))
require.ErrorContainsf(s.T(), err, "no such contract", "error message: %s", err)
}

Expand All @@ -55,9 +67,13 @@ func (s *AnteTestSuite) TestSendCoinsWithLimitSendHook() {
contractAddr, _, err := s.WasmKeeper.Instantiate(s.Ctx, codeId, acc, acc, []byte("{}"), "limit send", sdk.NewCoins())
require.NoError(s.T(), err)

s.Ctx = s.Ctx.WithValue(smartaccounttypes.ModuleName, smartaccounttypes.Setting{
// set settings
err = s.SmartAccountKeeper.SetSetting(s.Ctx, smartaccounttypes.Setting{
Owner: acc.String(),
PreTransaction: []string{contractAddr.String()},
})
require.NoError(s.T(), err)

txBuilder := s.BuildDefaultMsgTx(0, &types.MsgSend{
FromAddress: acc.String(),
ToAddress: acc.String(),
Expand All @@ -76,9 +92,13 @@ func (s *AnteTestSuite) TestStakingWithLimitSendHook() {
contractAddr, _, err := s.WasmKeeper.Instantiate(s.Ctx, codeId, acc, acc, []byte("{}"), "limit send", sdk.NewCoins())
require.NoError(s.T(), err)

s.Ctx = s.Ctx.WithValue(smartaccounttypes.ModuleName, smartaccounttypes.Setting{
// set settings
err = s.SmartAccountKeeper.SetSetting(s.Ctx, smartaccounttypes.Setting{
Owner: acc.String(),
PreTransaction: []string{contractAddr.String()},
})
require.NoError(s.T(), err)

txBuilder := s.BuildDefaultMsgTx(0, &stakingtypes.MsgDelegate{
DelegatorAddress: acc.String(),
ValidatorAddress: acc.String(),
Expand Down

0 comments on commit 7663195

Please sign in to comment.