blockbook/bchain/coins/eth/dataparser_test.go
2023-03-02 00:37:33 +01:00

506 lines
29 KiB
Go

//go:build unittest
package eth
import (
"reflect"
"testing"
"github.com/trezor/blockbook/bchain"
)
func Test_parseSimpleStringProperty(t *testing.T) {
tests := []struct {
name string
args string
want string
}{
{
name: "1",
args: "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000758504c4f44444500000000000000000000000000000000000000000000000000",
want: "XPLODDE",
},
{
name: "2",
args: "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000022426974436c617665202d20436f6e73756d657220416374697669747920546f6b656e00000000000000",
want: "BitClave - Consumer Activity Token",
},
{
name: "short",
args: "0x44616920537461626c65636f696e2076312e3000000000000000000000000000",
want: "Dai Stablecoin v1.0",
},
{
name: "short2",
args: "0x44616920537461626c65636f696e2076312e3020444444444444444444444444",
want: "Dai Stablecoin v1.0 DDDDDDDDDDDD",
},
{
name: "long",
args: "0x556e6973776170205631000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
want: "Uniswap V1",
},
{
name: "garbage",
args: "0x2234880850896048596206002535425366538144616734015984380565810000",
want: "",
},
{
name: "garbage",
args: "6080604052600436106100225760003560e01c80630cbcae701461003957610031565b366100315761002f610077565b005b61002f610077565b34801561004557600080fd5b5061004e61014e565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b7f000000000000000000000000000000000000000000000000000000000000000061011c565b60043560601b60601c6bca11c0de15dead10cced00006000195460a01c036100e9577f696d706c6f63000000000000000000000000000000000000000000000000000060005260206000fd5b8060001955005b60405136810160405236600082376000803683600019545af43d6000833e80610117573d82fd5b503d81f35b80330361014357602436036101435763ca11c0de60003560e01c036101435761014361009d565b61014b6100f0565b50565b600073ffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff541660005260206000f3fea2646970667358221220f27ad3f3b75609baa5d26d65ec1001c4a59f38e89088d6b47517c1cd1faf22ab64736f6c634300080d0033",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := parseSimpleStringProperty(tt.args)
// the addresses could have different case
if got != tt.want {
t.Errorf("parseSimpleStringProperty = %v, want %v", got, tt.want)
}
})
}
}
func TestGetSignatureFromData(t *testing.T) {
tests := []struct {
name string
data string
want uint32
}{
{
name: "0x9e53a69a",
data: "0x9e53a69a000000000000000000000000000000000000000000000",
want: 2656282266,
},
{
name: "9e53a69b",
data: "9e53a69b000000000000000000000000000000000000000000000",
want: 2656282267,
},
{
name: "0x9e53 short",
data: "0x9e53",
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetSignatureFromData(tt.data); got != tt.want {
t.Errorf("GetSignatureFromData() = %v, want %v", got, tt.want)
}
})
}
}
func TestParseInputData(t *testing.T) {
signatures := []bchain.FourByteSignature{
{
Name: "mintFighter",
Parameters: []string{},
},
{
Name: "cancelMultipleMakerOrders",
Parameters: []string{"uint256[]"},
},
{
Name: "mockRegisterFact",
Parameters: []string{"bytes32"},
},
{
Name: "vestingDeposits",
Parameters: []string{"address"},
},
{
Name: "addLiquidityETHToContract",
Parameters: []string{"address", "uint256", "uint256", "uint256", "address", "uint256"},
},
{
Name: "spread",
Parameters: []string{"uint256", "address[]"},
},
{
Name: "registerWithConfig",
Parameters: []string{"string", "address", "uint256", "bytes32", "address", "address"},
},
{
Name: "atomicMatch_",
Parameters: []string{"address[14]", "uint256[18]", "uint8[8]", "bytes", "bytes", "bytes", "bytes", "bytes", "bytes", "uint8[2]", "bytes32[5]"},
},
{
Name: "transmitAndSellTokenForEth",
Parameters: []string{"address", "uint256", "uint256", "uint256", "address", "(uint8,bytes32,bytes32)", "bytes"},
},
{
Name: "execute",
Parameters: []string{"bytes", "bytes[]", "uint256"},
},
}
tests := []struct {
name string
signatures *[]bchain.FourByteSignature
data string
want *bchain.EthereumParsedInputData
wantErr bool
}{
{
name: "transfer",
signatures: &signatures,
data: "",
want: &bchain.EthereumParsedInputData{
Name: "Transfer",
},
},
{
name: "mintFighter",
signatures: &signatures,
data: "0xa19b9082",
want: &bchain.EthereumParsedInputData{
MethodId: "0xa19b9082",
Name: "Mint Fighter",
Function: "mintFighter()",
Params: []bchain.EthereumParsedInputParam{},
},
},
{
name: "mockRegisterFact",
signatures: &signatures,
data: "0xf69507abdc8fa8fe57a22de66a1d5898496c524068cb04c31f72497b3ac9f3b449e58725",
want: &bchain.EthereumParsedInputData{
MethodId: "0xf69507ab",
Name: "Mock Register Fact",
Function: "mockRegisterFact(bytes32)",
Params: []bchain.EthereumParsedInputParam{
{
Type: "bytes32",
Values: []string{"0xdc8fa8fe57a22de66a1d5898496c524068cb04c31f72497b3ac9f3b449e58725"},
},
},
},
},
{
name: "cancelMultipleMakerOrders",
signatures: &signatures,
data: "0x9e53a69a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000017f62f8db30",
want: &bchain.EthereumParsedInputData{
MethodId: "0x9e53a69a",
Name: "Cancel Multiple Maker Orders",
Function: "cancelMultipleMakerOrders(uint256[])",
Params: []bchain.EthereumParsedInputParam{
{
Type: "uint256[]",
Values: []string{"1646632950576"},
},
},
},
},
{
name: "addLiquidityETHToContract",
signatures: &signatures,
data: "0xf305d719000000000000000000000000b80e5aaa2131c07568128f68b8538ed3c8951234000000000000000000000000000000000000007e37be2022c0914b2680000000000000000000000000000000000000000000007e37be2022c0914b26800000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000009f64b014ca26f2def573246543dd1115b229e4f400000000000000000000000000000000000000000000000000000000623f56f8",
want: &bchain.EthereumParsedInputData{
MethodId: "0xf305d719",
Name: "Add Liquidity ETH To Contract",
Function: "addLiquidityETHToContract(address, uint256, uint256, uint256, address, uint256)",
Params: []bchain.EthereumParsedInputParam{
{
Type: "address",
Values: []string{"0xB80e5AaA2131c07568128f68b8538eD3C8951234"},
},
{
Type: "uint256",
Values: []string{"10000000000000000000000000000000"},
},
{
Type: "uint256",
Values: []string{"10000000000000000000000000000000"},
},
{
Type: "uint256",
Values: []string{"1000000000000000000"},
},
{
Type: "address",
Values: []string{"0x9f64B014CA26F2DeF573246543DD1115b229e4F4"},
},
{
Type: "uint256",
Values: []string{"1648318200"},
},
},
},
},
{
name: "addLiquidityETHToContract data don't match - too long",
signatures: &signatures,
data: "0xf305d719000000000000000000000000b80e5aaa2131c07568128f68b8538ed3c8951234000000000000000000000000000000000000007e37be2022c0914b2680000000000000000000000000000000000000000000007e37be2022c0914b26800000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000009f64b014ca26f2def573246543dd1115b229e4f400000000000000000000000000000000000000000000000000000000623f56f800000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
want: &bchain.EthereumParsedInputData{
MethodId: "0xf305d719",
},
},
{
name: "addLiquidityETHToContract data don't match - too short",
signatures: &signatures,
data: "0xf305d719000000000000000000000000b80e5aaa2131c07568128f68b8538ed3c8951234000000000000000000000000000000000000007e37be2022c0914b2680000000000000000000000000000000000000000000007e37be2022c0914b26800000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000009f64b014ca26f2def573246543dd1115b229e4f4",
want: &bchain.EthereumParsedInputData{
MethodId: "0xf305d719",
},
},
{
name: "spread",
signatures: &signatures,
data: "0xcd51b093000000000000000000000000000000000000000000000000016345785d8a00000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000048c999d9206fcf2a0ecde10049de6dc2d1704bb2000000000000000000000000d2dae6b2309ada5d4c983b4c7d2c942452adc759",
want: &bchain.EthereumParsedInputData{
MethodId: "0xcd51b093",
Name: "Spread",
Function: "spread(uint256, address[])",
Params: []bchain.EthereumParsedInputParam{
{
Type: "uint256",
Values: []string{"100000000000000000"},
},
{
Type: "address[]",
Values: []string{"0x48c999d9206fcf2A0ecdE10049de6Dc2d1704Bb2", "0xD2DAE6B2309aDa5d4c983B4c7D2c942452aDC759"},
},
},
},
},
{
name: "atomicMatch_", // mainnet tx 0x57aff22b0f812e05467fb73caec8ac0364a535382496e5f64eb9df9fb32bd85f
signatures: &signatures,
data: "0xab834bab0000000000000000000000007f268357a8c2552623316e2562d90e642bb538e50000000000000000000000001676b0ab0aeb83122c58abc3d6a50b6c4a9d376300000000000000000000000024c57fbb5c260edf158583818177cfd5c2dec4700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000baf2127b49fc93cbca6269fade0f7f31df4c88a7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007f268357a8c2552623316e2562d90e642bb538e500000000000000000000000024c57fbb5c260edf158583818177cfd5c2dec47000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005b3256965e7c3cf26e11fcaf296dfc8807c01073000000000000000000000000baf2127b49fc93cbca6269fade0f7f31df4c88a70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062531f6400000000000000000000000000000000000000000000000000000000000000000227db897c05fe6409bc72c6bee932b99a92ca45e155cf85e763424e7a3ee61500000000000000000000000000000000000000000000000000000000000002ee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000625313f800000000000000000000000000000000000000000000000000000000627aa14b79166058af7dd96e2190730f926c56d6131af9d72b4dd2138b58c30e268c7f300000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000006a000000000000000000000000000000000000000000000000000000000000007c000000000000000000000000000000000000000000000000000000000000008e00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b200000000000000000000000000000000000000000000000000000000000000b20000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001c77e6196859305642ea4751b9597a9507472acb04b9f1f4759aa0f27af41edd8960513f1649f58782cacce26b1341575b584594f940bba0614aff302d25b4b10477e6196859305642ea4751b9597a9507472acb04b9f1f4759aa0f27af41edd8960513f1649f58782cacce26b1341575b584594f940bba0614aff302d25b4b104000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4fb16a59500000000000000000000000000000000000000000000000000000000000000000000000000000000000000001676b0ab0aeb83122c58abc3d6a50b6c4a9d3763000000000000000000000000f25f4f4f6517101dc947d1c0370571ebdd25f14a00000000000000000000000000000000000000000000000000000000000002c7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4fb16a59500000000000000000000000024c57fbb5c260edf158583818177cfd5c2dec4700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f25f4f4f6517101dc947d1c0370571ebdd25f14a00000000000000000000000000000000000000000000000000000000000002c7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e400000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
want: &bchain.EthereumParsedInputData{
MethodId: "0xab834bab",
Name: "Atomic Match_",
Function: "atomicMatch_(address[14], uint256[18], uint8[8], bytes, bytes, bytes, bytes, bytes, bytes, uint8[2], bytes32[5])",
Params: []bchain.EthereumParsedInputParam{
{
Type: "address[14]",
Values: []string{
"0x7f268357A8c2552623316e2562D90e642bB538E5", "0x1676b0AB0Aeb83122C58ABC3d6a50B6c4A9d3763", "0x24C57FBB5c260EDf158583818177Cfd5C2dec470", "0x0000000000000000000000000000000000000000",
"0xBAf2127B49fC93CbcA6269FAdE0F7F31dF4c88a7", "0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000", "0x7f268357A8c2552623316e2562D90e642bB538E5",
"0x24C57FBB5c260EDf158583818177Cfd5C2dec470", "0x0000000000000000000000000000000000000000", "0x5b3256965e7C3cF26E11FCAf296DfC8807C01073", "0xBAf2127B49fC93CbcA6269FAdE0F7F31dF4c88a7",
"0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000"},
},
{
Type: "uint256[18]",
Values: []string{
"750", "0", "0", "0", "10000000000000000", "0", "1649614692", "0", "975047921716720136517384107537725863826800092678142650456874303300963329557",
"750", "0", "0", "0", "10000000000000000", "0", "1649611768", "1652203851", "54769390272606378508076535204478407261307419838517394120712398796227861053232"},
},
{
Type: "uint8[8]",
Values: []string{"1", "0", "0", "1", "1", "1", "0", "1"},
},
{
Type: "bytes",
Values: []string{"0xfb16a59500000000000000000000000000000000000000000000000000000000000000000000000000000000000000001676b0ab0aeb83122c58abc3d6a50b6c4a9d3763000000000000000000000000f25f4f4f6517101dc947d1c0370571ebdd25f14a00000000000000000000000000000000000000000000000000000000000002c7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000"},
},
{
Type: "bytes",
Values: []string{"0xfb16a59500000000000000000000000024c57fbb5c260edf158583818177cfd5c2dec4700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f25f4f4f6517101dc947d1c0370571ebdd25f14a00000000000000000000000000000000000000000000000000000000000002c7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000"},
},
{
Type: "bytes",
Values: []string{"0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},
},
{
Type: "bytes",
Values: []string{"0x000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},
},
{
Type: "bytes",
Values: []string{""},
},
{
Type: "bytes",
Values: []string{""},
},
{
Type: "uint8[2]",
Values: []string{"28", "28"},
},
{
Type: "bytes32[5]",
Values: []string{"0x77e6196859305642ea4751b9597a9507472acb04b9f1f4759aa0f27af41edd89", "0x60513f1649f58782cacce26b1341575b584594f940bba0614aff302d25b4b104",
"0x77e6196859305642ea4751b9597a9507472acb04b9f1f4759aa0f27af41edd89", "0x60513f1649f58782cacce26b1341575b584594f940bba0614aff302d25b4b104",
"0x0000000000000000000000000000000000000000000000000000000000000000"},
},
},
},
},
{
name: "registerWithConfig",
signatures: &signatures,
data: "0xf7a1696300000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000769cbf44073741ccb4c39c945402130b46fa8a70000000000000000000000000000000000000000000000000000000012cf35707a8c22626793047f41a428e815e2bb12ced6d5db4246a8b0bda488c541647bef0000000000000000000000004976fb03c32e5b8cfe2b6ccb31c09ba78ebaba410000000000000000000000000769cbf44073741ccb4c39c945402130b46fa8a700000000000000000000000000000000000000000000000000000000000000076d6f6e7369746100000000000000000000000000000000000000000000000000",
want: &bchain.EthereumParsedInputData{
MethodId: "0xf7a16963",
Name: "Register With Config",
Function: "registerWithConfig(string, address, uint256, bytes32, address, address)",
Params: []bchain.EthereumParsedInputParam{
{
Type: "string",
Values: []string{"monsita"},
},
{
Type: "address",
Values: []string{"0x0769cBf44073741cCb4C39c945402130B46fa8A7"},
},
{
Type: "uint256",
Values: []string{"315569520"},
},
{
Type: "bytes32",
Values: []string{"0x7a8c22626793047f41a428e815e2bb12ced6d5db4246a8b0bda488c541647bef"},
},
{
Type: "address",
Values: []string{"0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41"},
},
{
Type: "address",
Values: []string{"0x0769cBf44073741cCb4C39c945402130B46fa8A7"},
},
},
},
},
{
name: "execute",
signatures: &signatures,
data: "0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000063fd167b00000000000000000000000000000000000000000000000000000000000000010800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000021e19e0c9bab2400000000000000000000000000000000000000000000000000000000000002fa5e9a300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000cda4e840411c00a614ad9205caec807c7458a0e3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
want: &bchain.EthereumParsedInputData{
MethodId: "0x3593564c",
Name: "Execute",
Function: "execute(bytes, bytes[], uint256)",
Params: []bchain.EthereumParsedInputParam{
{
Type: "bytes",
Values: []string{"0x08"},
},
{
Type: "bytes[]",
Values: []string{"0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000021e19e0c9bab2400000000000000000000000000000000000000000000000000000000000002fa5e9a300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000cda4e840411c00a614ad9205caec807c7458a0e3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"},
},
{
Type: "uint256",
Values: []string{"1677530747"},
},
},
},
},
{
name: "execute2",
signatures: &signatures,
data: "0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000063ffd82300000000000000000000000000000000000000000000000000000000000000020b080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000006f05b59d3b200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000006f05b59d3b20000000000000000000000000000000000000000000000491478480c282e75df8b5700000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000f0f9d895aca5c8678f706fb8216fa22957685a13",
want: &bchain.EthereumParsedInputData{
MethodId: "0x3593564c",
Name: "Execute",
Function: "execute(bytes, bytes[], uint256)",
Params: []bchain.EthereumParsedInputParam{
{
Type: "bytes",
Values: []string{"0x0b08"},
},
{
Type: "bytes[]",
Values: []string{
"0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000006f05b59d3b20000",
"0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000006f05b59d3b20000000000000000000000000000000000000000000000491478480c282e75df8b5700000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000f0f9d895aca5c8678f706fb8216fa22957685a13",
},
},
{
Type: "uint256",
Values: []string{"1677711395"},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ParseInputData(tt.signatures, tt.data)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseInputData() = %v, want %v", got, tt.want)
}
})
}
}
func Test_getEnsRecord(t *testing.T) {
tests := []struct {
name string
log rpcLogWithTxHash
want *bchain.AddressAliasRecord
}{
{
name: "unraveled",
log: rpcLogWithTxHash{
RpcLog: bchain.RpcLog{
Address: "0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5",
Topics: []string{
"0xca6abbe9d7f11422cb6ca7629fbf6fe9efb1c621f71ce8f02b9f2a230097404f",
"0x40ce2aa8cd9ee9fef4bf3a68abab7fbcceb6bac89370518caf6a602cefe836bd",
"0x0000000000000000000000002c630b16aa53ae0189880e15c23323688acb607c",
},
Data: "0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000017629245f5a86f0000000000000000000000000000000000000000000000000000000069dbb21d0000000000000000000000000000000000000000000000000000000000000009756e726176656c65640000000000000000000000000000000000000000000000",
},
},
want: &bchain.AddressAliasRecord{Address: "0x2C630b16Aa53ae0189880e15C23323688acb607c", Name: "unraveled"},
},
{
name: "4x unraveled",
log: rpcLogWithTxHash{
RpcLog: bchain.RpcLog{
Address: "0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5",
Topics: []string{
"0xca6abbe9d7f11422cb6ca7629fbf6fe9efb1c621f71ce8f02b9f2a230097404f",
"0x40ce2aa8cd9ee9fef4bf3a68abab7fbcceb6bac89370518caf6a602cefe836bd",
"0x0000000000000000000000002c630b16aa53ae0189880e15c23323688acb607c",
},
Data: "0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000017629245f5a86f0000000000000000000000000000000000000000000000000000000069dbb21d0000000000000000000000000000000000000000000000000000000000000024756e726176656c6564756e726176656c6564756e726176656c6564756e726176656c656400000000000000000000000000000000000000000000000000000000",
},
},
want: &bchain.AddressAliasRecord{Address: "0x2C630b16Aa53ae0189880e15C23323688acb607c", Name: "unraveledunraveledunraveledunraveled"},
},
{
name: "no signature",
log: rpcLogWithTxHash{
RpcLog: bchain.RpcLog{
Address: "0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5",
Topics: []string{
"0xca6abbe9d7f11422cb6ca7629fbf6fe9efb1c621f71ce8f02b9f2a230097404e",
"0x40ce2aa8cd9ee9fef4bf3a68abab7fbcceb6bac89370518caf6a602cefe836bd",
"0x0000000000000000000000002c630b16aa53ae0189880e15c23323688acb607c",
},
Data: "0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000017629245f5a86f0000000000000000000000000000000000000000000000000000000069dbb21d0000000000000000000000000000000000000000000000000000000000000009756e726176656c65640000000000000000000000000000000000000000000000",
},
},
want: nil,
},
{
name: "name length does not match",
log: rpcLogWithTxHash{
RpcLog: bchain.RpcLog{
Address: "0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5",
Topics: []string{
"0xca6abbe9d7f11422cb6ca7629fbf6fe9efb1c621f71ce8f02b9f2a230097404f",
"0x40ce2aa8cd9ee9fef4bf3a68abab7fbcceb6bac89370518caf6a602cefe836bd",
"0x0000000000000000000000002c630b16aa53ae0189880e15c23323688acb607c",
},
Data: "0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000017629245f5a86f0000000000000000000000000000000000000000000000000000000069dbb21d0000000000000000000000000000000000000000000000000000000000000ff9756e726176656c65640000000000000000000000000000000000000000000000",
},
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getEnsRecord(&tt.log); !reflect.DeepEqual(got, tt.want) {
t.Errorf("getEnsRecord() = %v, want %v", got, tt.want)
}
})
}
}