cosmos-sdk/x/authz/simulation/decoder_test.go
MD Aleem 21295060ab
fix: remove time.now check from authz (#11129)
* Merge pull request from GHSA-2p6r-37p9-89p2

* test: adding authz grant tests

* fix TestCLITxGrantAuthorization/Invalid_expiration_time test case

* comment out the test

* reenable test

* master update

* update changelog and cli test

* fix keeper tests

* fix decoder test

* cleaning

* wip - tests

* fix cli test

* add a comment

* update TestMsgGrantAuthorization

* udpate changelog

* fix sims

* fix sims

* update changelog

* Update x/authz/authorization_grant.go

Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
2022-02-07 15:38:45 +01:00

54 lines
1.3 KiB
Go

package simulation_test
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
"github.com/cosmos/cosmos-sdk/x/authz/simulation"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
func TestDecodeStore(t *testing.T) {
cdc := simapp.MakeTestEncodingConfig().Codec
dec := simulation.NewDecodeStore(cdc)
now := time.Now().UTC()
grant, _ := authz.NewGrant(now, banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123))), now.Add(1))
grantBz, err := cdc.Marshal(&grant)
require.NoError(t, err)
kvPairs := kv.Pairs{
Pairs: []kv.Pair{
{Key: []byte(keeper.GrantKey), Value: grantBz},
{Key: []byte{0x99}, Value: []byte{0x99}},
},
}
tests := []struct {
name string
expectErr bool
expectedLog string
}{
{"Grant", false, fmt.Sprintf("%v\n%v", grant, grant)},
{"other", true, ""},
}
for i, tt := range tests {
i, tt := i, tt
t.Run(tt.name, func(t *testing.T) {
if tt.expectErr {
require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
} else {
require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name)
}
})
}
}