From 4c733526326a25a50d578345a4a35d712cee911e Mon Sep 17 00:00:00 2001 From: zsystm <124245155+zsystm@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:00:00 +0900 Subject: [PATCH] test(evmengine): add test cases for params (#136) increased coverage to 77.3% --- .../evmengine/keeper/params_internal_test.go | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 client/x/evmengine/keeper/params_internal_test.go diff --git a/client/x/evmengine/keeper/params_internal_test.go b/client/x/evmengine/keeper/params_internal_test.go new file mode 100644 index 00000000..e5b40a9d --- /dev/null +++ b/client/x/evmengine/keeper/params_internal_test.go @@ -0,0 +1,48 @@ +package keeper + +import ( + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" + + "github.com/piplabs/story/client/x/evmengine/types" +) + +func TestKeeper_ExecutionBlockHash(t *testing.T) { + t.Parallel() + ctx, keeper := createTestKeeper(t) + + // check existing execution block hash + execHash, err := keeper.ExecutionBlockHash(ctx) + require.NoError(t, err) + require.Nil(t, execHash, "execution block hash should be nil because it is not set yet") + + // set execution block hash + dummyHash := common.HexToHash("0x047e24c3455107d87c68dffa307b3b7fa1877f3e9d7f30c7ee359f2eff3a75d9") + require.NoError(t, keeper.SetParams(ctx, types.Params{ExecutionBlockHash: dummyHash.Bytes()})) + + // check execution block hash whether it is set correctly + execHash, err = keeper.ExecutionBlockHash(ctx) + require.NoError(t, err) + require.Equal(t, dummyHash.Bytes(), execHash, "execution block hash should be equal to the dummy hash") +} + +func TestKeeper_GetSetParams(t *testing.T) { + t.Parallel() + ctx, keeper := createTestKeeper(t) + + // check existing params + params, err := keeper.GetParams(ctx) + require.NoError(t, err) + require.Equal(t, types.DefaultParams(), params, "params should be equal to the default params") + + // set execution block hash + dummyHash := common.HexToHash("0x047e24c3455107d87c68dffa307b3b7fa1877f3e9d7f30c7ee359f2eff3a75d9") + require.NoError(t, keeper.SetParams(ctx, types.Params{ExecutionBlockHash: dummyHash.Bytes()})) + + // check params whether it is set correctly + params, err = keeper.GetParams(ctx) + require.NoError(t, err) + require.Equal(t, types.Params{ExecutionBlockHash: dummyHash.Bytes()}, params) +}