Skip to content

Commit

Permalink
abiparse: add test for unnamed fields
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Oct 17, 2023
1 parent 9c1d4a8 commit 7eb259b
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
36 changes: 36 additions & 0 deletions analyzer/runtime/abiparse/abiparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "embed"
"encoding/hex"
"encoding/json"
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -49,6 +50,41 @@ func TestParseTypes(t *testing.T) {
}
}

func TestParseTxUnnamed(t *testing.T) {
data, err := hex.DecodeString("ee799b1800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002")
require.NoError(t, err)
result, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004")
require.NoError(t, err)
method, args, err := ParseData(data, Varied)
require.NoError(t, err)
fmt.Printf("method %s\n", method)
fmt.Printf("args %#v\n", args)
outArgs, err := ParseResult(result, method)
require.NoError(t, err)
fmt.Printf("outArgs %#v\n", outArgs)
}

func TestParseEventUnnamed(t *testing.T) {
topicsHex := []string{
"54789e7ea9ad7e0cf2c8e336a0e24206777d784a11ec566b33ae6402ee7c2518",
"0000000000000000000000000000000000000000000000000000000000000001",
"0000000000000000000000000000000000000000000000000000000000000002",
}
topics := make([][]byte, 0, len(topicsHex))
for _, topicHex := range topicsHex {
topic, err := hex.DecodeString(topicHex)
require.NoError(t, err)
topics = append(topics, topic)
}
fmt.Printf("topics %#v\n", topics)
data, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004")
require.NoError(t, err)
event, args, err := ParseEvent(topics, data, Varied)
require.NoError(t, err)
fmt.Printf("event %s\n", event)
fmt.Printf("args %#v\n", args)
}

func TestParseTx(t *testing.T) {
// https://explorer.emerald.oasis.dev/tx/0x1ac7521df4cda38c87cff56b1311ee9362168bd794230415a37f2aff3a554a5f/internal-transactions
data, err := hex.DecodeString("095ea7b3000000000000000000000000250d48c5e78f1e85f7ab07fec61e93ba703ae6680000000000000000000000000000000000000000000000003782dace9d900000")
Expand Down
2 changes: 2 additions & 0 deletions analyzer/runtime/abiparse/test_contracts/Varied.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ interface Varied {
uint8[] calldata l8,
O calldata o
) external;
function testAnon(uint16, uint16) external returns (uint16, uint16);
event TestAnon(uint16 indexed, uint16 indexed, uint16, uint16);
}
63 changes: 62 additions & 1 deletion analyzer/runtime/abiparse/test_contracts/artifacts/Varied.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,42 @@
},
"gasEstimates": null,
"methodIdentifiers": {
"test(int8,uint8,int256,uint256,bool,bytes32,address,function,uint16[2],uint8[2],bytes,string,uint16[],uint8[],(uint16,string))": "b23a194f"
"test(int8,uint8,int256,uint256,bool,bytes32,address,function,uint16[2],uint8[2],bytes,string,uint16[],uint8[],(uint16,string))": "b23a194f",
"testUnnamed(uint16,uint16)": "ee799b18"
}
},
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint16",
"name": "",
"type": "uint16"
},
{
"indexed": true,
"internalType": "uint16",
"name": "",
"type": "uint16"
},
{
"indexed": false,
"internalType": "uint16",
"name": "",
"type": "uint16"
},
{
"indexed": false,
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"name": "TestUnnamed",
"type": "event"
},
{
"inputs": [
{
Expand Down Expand Up @@ -147,6 +179,35 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint16",
"name": "",
"type": "uint16"
},
{
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"name": "testUnnamed",
"outputs": [
{
"internalType": "uint16",
"name": "",
"type": "uint16"
},
{
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
}

0 comments on commit 7eb259b

Please sign in to comment.