Commit ed0d8480 authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: cleanup

parent 6d049fea
...@@ -3,7 +3,7 @@ package safe ...@@ -3,7 +3,7 @@ package safe
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" //"fmt"
"math/big" "math/big"
"os" "os"
"testing" "testing"
...@@ -35,6 +35,7 @@ func testBatchJSON(t *testing.T, path string) { ...@@ -35,6 +35,7 @@ func testBatchJSON(t *testing.T, path string) {
require.JSONEq(t, string(b), string(data)) require.JSONEq(t, string(b), string(data))
} }
// TestBatchAddCallFinalizeWithdrawalTransaction ensures that structs can be serialized correctly.
func TestBatchAddCallFinalizeWithdrawalTransaction(t *testing.T) { func TestBatchAddCallFinalizeWithdrawalTransaction(t *testing.T) {
file, err := os.ReadFile("testdata/portal-abi.json") file, err := os.ReadFile("testdata/portal-abi.json")
require.NoError(t, err) require.NoError(t, err)
...@@ -58,11 +59,15 @@ func TestBatchAddCallFinalizeWithdrawalTransaction(t *testing.T) { ...@@ -58,11 +59,15 @@ func TestBatchAddCallFinalizeWithdrawalTransaction(t *testing.T) {
value := big.NewInt(222) value := big.NewInt(222)
require.NoError(t, batch.AddCall(to, value, sig, argument, portalABI)) require.NoError(t, batch.AddCall(to, value, sig, argument, portalABI))
d, err := json.MarshalIndent(batch, " ", " ") expected, err := os.ReadFile("testdata/finalize-withdrawal-tx.json")
require.NoError(t, err) require.NoError(t, err)
fmt.Println(string(d))
serialized, err := json.Marshal(batch)
require.NoError(t, err)
require.JSONEq(t, string(expected), string(serialized))
} }
// TestBatchAddCallDespostTransaction ensures that simple calls can be serialized correctly.
func TestBatchAddCallDespostTransaction(t *testing.T) { func TestBatchAddCallDespostTransaction(t *testing.T) {
file, err := os.ReadFile("testdata/portal-abi.json") file, err := os.ReadFile("testdata/portal-abi.json")
require.NoError(t, err) require.NoError(t, err)
...@@ -82,7 +87,10 @@ func TestBatchAddCallDespostTransaction(t *testing.T) { ...@@ -82,7 +87,10 @@ func TestBatchAddCallDespostTransaction(t *testing.T) {
} }
require.NoError(t, batch.AddCall(to, value, sig, argument, portalABI)) require.NoError(t, batch.AddCall(to, value, sig, argument, portalABI))
d, err := json.MarshalIndent(batch, " ", " ") expected, err := os.ReadFile("testdata/deposit-tx.json")
require.NoError(t, err)
serialized, err := json.Marshal(batch)
require.NoError(t, err) require.NoError(t, err)
fmt.Println(string(d)) require.JSONEq(t, string(expected), string(serialized))
} }
{
"version": "",
"chainId": "",
"createdAt": 0,
"meta": {
"createdFromSafeAddress": "",
"createdFromOwnerAddress": "",
"name": "",
"description": ""
},
"transactions": [
{
"to": "0x0000000000000000000000000000000000000001",
"value": "222",
"data": "0xe9e05c42000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000",
"contractMethod": {
"inputs": [
{
"internalType": "address",
"name": "_to",
"type": "address"
},
{
"internalType": "uint256",
"name": "_value",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "_gasLimit",
"type": "uint64"
},
{
"internalType": "bool",
"name": "_isCreation",
"type": "bool"
},
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
],
"name": "depositTransaction",
"payable": false
},
"contractInputsValues": {
"_data": "0x",
"_gasLimit": "100",
"_isCreation": "false",
"_to": "0x0100000000000000000000000000000000000000",
"_value": "2"
}
}
]
}
{
"version": "",
"chainId": "",
"createdAt": 0,
"meta": {
"createdFromSafeAddress": "",
"createdFromOwnerAddress": "",
"name": "",
"description": ""
},
"transactions": [
{
"to": "0x0000000000000000000000000000000000000001",
"value": "222",
"data": "0x8c3152e900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000",
"contractMethod": {
"inputs": [
{
"internalType": "TypesWithdrawalTransaction",
"name": "_tx",
"type": "tuple",
"components": [
{
"internalType": "uint256",
"name": "nonce",
"type": "uint256"
},
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "target",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "gasLimit",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
]
}
],
"name": "finalizeWithdrawalTransaction",
"payable": false
},
"contractInputsValues": {
"_tx": "[0,0x0000000000000000000000000000000000000001,0x0000000000000000000000000000000000000002,1,2,0x]"
}
}
]
}
{"version":"1.0","chainId":"1","createdAt":1692061927446,"meta":{"name":"Transactions Batch","description":"","txBuilderVersion":"1.16.1","createdFromSafeAddress":"0xc9D26D376dD75573E0C3247C141881F053d27Ae8","createdFromOwnerAddress":"","checksum":"0x9d01f75b6ab0cb240db3e3be44efdb96d64b2c88ef160bb13f46f279845c1a72"},"transactions":[{"to":"0x9e760aBd847E48A56b4a348Cba56Ae7267FeCE80","value":"0","data":null,"contractMethod":{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct Types.WithdrawalTransaction","name":"_tx","type":"tuple"}],"name":"finalizeWithdrawalTransaction","payable":false},"contractInputsValues":{"_tx":"[0,\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\",0,0,\"0x\"]"}}]}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment