laconicd-deprecated/x/evm/simulation/decoder_test.go
Adu 4ea9b6dc6d
imp, ci: address pending issues from EVM simulation (#1063)
* add note

fix note

* add TestAppStateFn TestRandomAccounts

* marshal int slice to json

* add paramschange for enableCreate and enableCall

* AppStateFn -> StateFn

* add TestDecodeStore

* update github actions to run evm simulation

* add TestParamChanges

* add TestRandomizedGenState

* use go install for runsim

* resolve conflict

* use random gasCap to estimate gas

* use estimateGas to calculate max transferableAmount

* update godoc

* TestAppStateFn -> TestStateFn

* Update x/evm/simulation/genesis.go

* comment

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-05-02 15:27:43 +02:00

48 lines
1.1 KiB
Go

package simulation
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/ethereum/go-ethereum/common"
"github.com/tharsis/ethermint/x/evm/types"
)
// TestDecodeStore tests that evm simulation decoder decodes the key value pairs as expected.
func TestDecodeStore(t *testing.T) {
dec := NewDecodeStore()
hash := common.BytesToHash([]byte("hash"))
code := common.Bytes2Hex([]byte{1, 2, 3})
kvPairs := kv.Pairs{
Pairs: []kv.Pair{
{Key: types.KeyPrefixCode, Value: common.FromHex(code)},
{Key: types.KeyPrefixStorage, Value: hash.Bytes()},
},
}
tests := []struct {
name string
expectedLog string
}{
{"Code", fmt.Sprintf("%v\n%v", code, code)},
{"Storage", fmt.Sprintf("%v\n%v", hash, hash)},
{"other", ""},
}
for i, tt := range tests {
i, tt := i, tt
t.Run(tt.name, func(t *testing.T) {
switch i {
case len(tests) - 1:
require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
default:
require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name)
}
})
}
}