Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(evmengine): add test cases for params #137

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions client/x/evmengine/types/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package types_test

import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

"github.com/piplabs/story/client/x/evmengine/types"
)

func TestNewParams(t *testing.T) {
t.Parallel()

dummyHash := common.HexToHash("0x047e24c3455107d87c68dffa307b3b7fa1877f3e9d7f30c7ee359f2eff3a75d9")
tcs := []struct {
name string
executionBlockHash []byte
expectedResult types.Params
}{
{
name: "non-nil execution block hash",
executionBlockHash: dummyHash.Bytes(),
expectedResult: types.Params{
ExecutionBlockHash: dummyHash.Bytes(),
},
},
{
name: "nil execution block hash",
executionBlockHash: nil,
expectedResult: types.Params{
ExecutionBlockHash: nil,
},
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

result := types.NewParams(tc.executionBlockHash)
require.Equal(t, tc.expectedResult, result)
})
}
}

func TestDefaultParams(t *testing.T) {
t.Parallel()

result := types.DefaultParams()
require.Equal(t, types.Params{
ExecutionBlockHash: nil,
}, result)
}

func TestValidateExecutionBlockHash(t *testing.T) {
t.Parallel()

dummyHash := common.HexToHash("0x047e24c3455107d87c68dffa307b3b7fa1877f3e9d7f30c7ee359f2eff3a75d9")
tcs := []struct {
name string
executionBlockHash []byte
expectedError string
}{
{
name: "pass: valid execution block hash",
executionBlockHash: dummyHash.Bytes(),
},
{
name: "fail: invalid execution block hash",
executionBlockHash: []byte("invalid"),
expectedError: "invalid execution block hash length",
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

err := types.ValidateExecutionBlockHash(tc.executionBlockHash)
if tc.expectedError == "" {
require.NoError(t, err)
} else {
require.EqualError(t, err, tc.expectedError)
}
})
}
}
Loading