forked from piplabs/story
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test cases for params (piplabs#137)
increased coverage to 100%
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |