-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14f8a2c
commit db03210
Showing
12 changed files
with
227 additions
and
46 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
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
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
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,73 @@ | ||
// Copyright (c) 2023-2024 Nibi, Inc. | ||
package rpc_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
cmt "github.com/cometbft/cometbft/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
gethcore "github.com/ethereum/go-ethereum/core/types" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/NibiruChain/nibiru/eth/rpc" | ||
"github.com/NibiruChain/nibiru/x/evm/evmtest" | ||
) | ||
|
||
type SuiteRPC struct { | ||
suite.Suite | ||
} | ||
|
||
func TestSuiteRPC(t *testing.T) { | ||
suite.Run(t, new(SuiteRPC)) | ||
} | ||
|
||
func (s *SuiteRPC) TestRawTxToEthTx() { | ||
type TestCase struct { | ||
tx cmt.Tx | ||
clientCtx client.Context | ||
wantErr string | ||
} | ||
type TestCaseSetupFn = func() TestCase | ||
|
||
for _, tcSetup := range []TestCaseSetupFn{ | ||
func() TestCase { | ||
_, _, clientCtx := evmtest.NewEthTxMsgAsCmt(s.T()) | ||
txBz := []byte("tx") | ||
return TestCase{ | ||
tx: txBz, // invalid bytes | ||
clientCtx: clientCtx, // valid clientCtx | ||
wantErr: "failed to unmarshal JSON", | ||
} | ||
}, | ||
func() TestCase { | ||
txBz, _, clientCtx := evmtest.NewEthTxMsgAsCmt(s.T()) | ||
return TestCase{ | ||
tx: txBz, // valid bytes | ||
clientCtx: clientCtx, // valid clientCtx | ||
wantErr: "", // happy | ||
} | ||
}, | ||
} { | ||
tc := tcSetup() | ||
ethTxs, err := rpc.RawTxToEthTx(tc.clientCtx, tc.tx) | ||
if tc.wantErr != "" { | ||
s.Require().ErrorContains(err, tc.wantErr, "ethTxs: %s", ethTxs) | ||
continue | ||
} | ||
s.Require().NoError(err, "ethTxs: %s", ethTxs) | ||
} | ||
} | ||
|
||
func (s *SuiteRPC) TestEthHeaderFromTendermint() { | ||
for _, block := range []*cmt.Block{ | ||
// Some happy path test cases for good measure | ||
cmt.MakeBlock(1, []cmt.Tx{}, nil, nil), | ||
cmt.MakeBlock(420, []cmt.Tx{}, nil, nil), | ||
} { | ||
ethHeader := rpc.EthHeaderFromTendermint( | ||
block.Header, gethcore.Bloom{}, sdkmath.NewInt(1).BigInt()) | ||
s.NotNil(ethHeader) | ||
s.Equal(block.Header.Height, ethHeader.Number.Int64()) | ||
} | ||
} |
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
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
Oops, something went wrong.