2018-04-04 17:39:38 +00:00
|
|
|
package transactions
|
2018-03-23 11:54:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2018-03-23 11:54:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSendTxArgsValidity(t *testing.T) {
|
|
|
|
// 1. If only data fields is set, valid and return data
|
|
|
|
|
2019-12-19 18:27:27 +00:00
|
|
|
bytes1 := types.HexBytes([]byte{0xAA, 0xBB, 0xCC, 0xDD})
|
|
|
|
bytes2 := types.HexBytes([]byte{0x00, 0x01, 0x02})
|
2018-03-23 11:54:09 +00:00
|
|
|
|
2019-12-19 18:27:27 +00:00
|
|
|
bytesEmpty := types.HexBytes([]byte{})
|
2018-03-23 11:54:09 +00:00
|
|
|
|
|
|
|
doSendTxValidityTest(t, SendTxArgs{}, true, nil)
|
|
|
|
doSendTxValidityTest(t, SendTxArgs{Input: bytes1}, true, bytes1)
|
|
|
|
doSendTxValidityTest(t, SendTxArgs{Data: bytes1}, true, bytes1)
|
|
|
|
doSendTxValidityTest(t, SendTxArgs{Input: bytes1, Data: bytes1}, true, bytes1)
|
|
|
|
doSendTxValidityTest(t, SendTxArgs{Input: bytes1, Data: bytes2}, false, nil)
|
|
|
|
doSendTxValidityTest(t, SendTxArgs{Input: bytes1, Data: bytesEmpty}, true, bytes1)
|
|
|
|
doSendTxValidityTest(t, SendTxArgs{Input: bytesEmpty, Data: bytes1}, true, bytes1)
|
|
|
|
doSendTxValidityTest(t, SendTxArgs{Input: bytesEmpty, Data: bytesEmpty}, true, bytesEmpty)
|
|
|
|
}
|
|
|
|
|
2019-12-19 18:27:27 +00:00
|
|
|
func doSendTxValidityTest(t *testing.T, args SendTxArgs, expectValid bool, expectValue types.HexBytes) {
|
2018-03-23 11:54:09 +00:00
|
|
|
assert.Equal(t, expectValid, args.Valid(), "Valid() returned unexpected value")
|
|
|
|
if expectValid {
|
|
|
|
assert.Equal(t, expectValue, args.GetInput(), "GetInput() returned unexpected value")
|
|
|
|
}
|
|
|
|
}
|