chore_: Validate multi tx type (#5619)

This commit is contained in:
Cuteivist 2024-07-31 06:45:11 +02:00 committed by GitHub
parent bacd4f5e5c
commit daef6ee030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -45,6 +45,10 @@ func (tm *TransactionManager) CreateMultiTransactionFromCommand(command *MultiTr
if multiTransaction.FromNetworkID == wallet_common.UnknownChainID && len(data) == 1 {
multiTransaction.FromNetworkID = data[0].ChainID
}
case MultiTransactionBridge:
break
default:
return nil, fmt.Errorf("unsupported multi transaction type: %v", multiTransaction.Type)
}
return multiTransaction, nil

View File

@ -319,7 +319,7 @@ func TestCreateMultiTransactionFromCommand(t *testing.T) {
var command *MultiTransactionCommand
// Test types that should get chainID from the data
mtTypes := []MultiTransactionType{MultiTransactionSend, MultiTransactionApprove, MultiTransactionSwap}
mtTypes := []MultiTransactionType{MultiTransactionSend, MultiTransactionApprove, MultiTransactionSwap, MultiTransactionType(7)}
for _, mtType := range mtTypes {
fromAmount := hexutil.Big(*big.NewInt(1000000000000000000))
@ -340,6 +340,11 @@ func TestCreateMultiTransactionFromCommand(t *testing.T) {
})
multiTransaction, err := tm.CreateMultiTransactionFromCommand(command, data)
if mtType > MultiTransactionApprove {
// Unsupported type
require.Error(t, err)
break
}
require.NoError(t, err)
require.NotNil(t, multiTransaction)
require.Equal(t, command.FromAddress, multiTransaction.FromAddress)