Skip to content

Commit

Permalink
add test for arbitraryFunction error;
Browse files Browse the repository at this point in the history
Signed-off-by: tcar <[email protected]>
  • Loading branch information
tcar121293 committed Oct 5, 2023
1 parent f023c91 commit 7234815
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
30 changes: 30 additions & 0 deletions chains/evm/deposithandlers/erc20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func testFunc(Config interface{}) error {
return nil
}

func testErrFunc(Config interface{}) error {
return errors.New("Error")
}

type Config struct{}

func TestRunErc20HandlerTestSuite(t *testing.T) {
Expand Down Expand Up @@ -76,6 +80,32 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() {
s.Equal(message, expected)
}

func (s *Erc20HandlerTestSuite) TestErc20HandleEventArbitraryFunctionError() {
// 0xf1e58fb17704c2da8479a533f9fad4ad0993ca6b
recipientByteSlice := []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107}

calldata := deposit.ConstructErc20DepositData(recipientByteSlice, big.NewInt(2))
depositLog := &eventhandlers.Deposit{
DestinationDomainID: 0,
ResourceID: [32]byte{0},
DepositNonce: 1,
SenderAddress: common.HexToAddress("0x4CEEf6139f00F9F4535Ad19640Ff7A0137708485"),
Data: calldata,
HandlerResponse: []byte{},
}

sourceID := uint8(1)

conf := &Config{}
erc20DepositHandler := deposithandlers.Erc20DepositHandler{
ArbitraryFunction: testErrFunc,
Config: conf,
}
_, err := erc20DepositHandler.HandleDeposit(sourceID, depositLog.DestinationDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse)

s.NotNil(err)
}

func (s *Erc20HandlerTestSuite) TestErc20HandleEventWithPriority() {
// 0xf1e58fb17704c2da8479a533f9fad4ad0993ca6b
recipientByteSlice := []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107}
Expand Down
24 changes: 24 additions & 0 deletions chains/evm/deposithandlers/erc721_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ func (s *Erc721HandlerTestSuite) TestErc721DepositHandlerEmptyMetadata() {
s.Equal(expected, m)
}

func (s *Erc721HandlerTestSuite) TestErc721DepositHandlerArbitraryFunctionError() {
recipient := common.HexToAddress("0xf1e58fb17704c2da8479a533f9fad4ad0993ca6b")

calldata := deposit.ConstructErc721DepositData(recipient.Bytes(), big.NewInt(2), []byte{})
depositLog := &eventhandlers.Deposit{
DestinationDomainID: 0,
ResourceID: [32]byte{0},
DepositNonce: 1,
Data: calldata,
HandlerResponse: []byte{},
}

sourceID := uint8(1)
conf := &Config{}

erc721DepositHandler := deposithandlers.Erc721DepositHandler{
ArbitraryFunction: testErrFunc,
Config: conf,
}
_, err := erc721DepositHandler.HandleDeposit(sourceID, depositLog.DestinationDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse)

s.NotNil(err)
}

func (s *Erc721HandlerTestSuite) TestErc721DepositHandlerIncorrectDataLen() {
metadata := []byte("0xdeadbeef")

Expand Down
32 changes: 32 additions & 0 deletions chains/evm/deposithandlers/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,35 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEvent() {
s.NotNil(message)
s.Equal(message, expected)
}

func (s *GenericHandlerTestSuite) TestGenericHandleEventArbitraryFunctionError() {
metadata := []byte("0xdeadbeef")
calldata := deposit.ConstructGenericDepositData(metadata)

depositLog := &eventhandlers.Deposit{
DestinationDomainID: 0,
ResourceID: [32]byte{0},
DepositNonce: 1,
SenderAddress: common.HexToAddress("0x4CEEf6139f00F9F4535Ad19640Ff7A0137708485"),
Data: calldata,
HandlerResponse: []byte{},
}

sourceID := uint8(1)

conf := &Config{}
genericDepositHandler := deposithandlers.GenericDepositHandler{
ArbitraryFunction: testErrFunc,
Config: conf,
}
_, err := genericDepositHandler.HandleDeposit(
sourceID,
depositLog.DestinationDomainID,
depositLog.DepositNonce,
depositLog.ResourceID,
depositLog.Data,
depositLog.HandlerResponse,
)

s.NotNil(err)
}

0 comments on commit 7234815

Please sign in to comment.