Commit 32b7ca19 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-chain-ops: Marshal withdrawalnetwork as int (#12584)

* op-chain-ops: Marshal withdrawalnetwork as int

* fix test

* lint

* fix other test

* swap networks
parent 3fbf88be
......@@ -45,9 +45,9 @@
"baseFeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000",
"l1FeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000",
"sequencerFeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000",
"baseFeeVaultWithdrawalNetwork": "remote",
"l1FeeVaultWithdrawalNetwork": "local",
"sequencerFeeVaultWithdrawalNetwork": "local",
"baseFeeVaultWithdrawalNetwork": 0,
"l1FeeVaultWithdrawalNetwork": 1,
"sequencerFeeVaultWithdrawalNetwork": 1,
"l1StandardBridgeProxy": "0x42000000000000000000000000000000000000f8",
"l1CrossDomainMessengerProxy": "0x42000000000000000000000000000000000000f9",
"l1ERC721BridgeProxy": "0x4200000000000000000000000000000000000060",
......
......@@ -72,3 +72,7 @@ func (w *WithdrawalNetwork) UnmarshalJSON(b []byte) error {
*w = s
return nil
}
func (w WithdrawalNetwork) MarshalJSON() ([]byte, error) {
return json.Marshal(int(w.ToUint8()))
}
......@@ -91,6 +91,12 @@ func TestWithdrawalNetworkInlineJSON(t *testing.T) {
"sequencerFeeVaultWithdrawalNetwork": "local"
}`
intJsonString := `{
"baseFeeVaultWithdrawalNetwork": 0,
"l1FeeVaultWithdrawalNetwork": 1,
"sequencerFeeVaultWithdrawalNetwork": 1
}`
t.Run("StringMarshaling", func(t *testing.T) {
decoded := new(tempNetworks)
require.NoError(t, json.Unmarshal([]byte(jsonString), decoded))
......@@ -101,15 +107,10 @@ func TestWithdrawalNetworkInlineJSON(t *testing.T) {
encoded, err := json.Marshal(decoded)
require.NoError(t, err)
require.JSONEq(t, jsonString, string(encoded))
require.JSONEq(t, intJsonString, string(encoded))
})
t.Run("IntMarshaling", func(t *testing.T) {
intJsonString := `{
"baseFeeVaultWithdrawalNetwork": 0,
"l1FeeVaultWithdrawalNetwork": 1,
"sequencerFeeVaultWithdrawalNetwork": 1
}`
decoded := new(tempNetworks)
require.NoError(t, json.Unmarshal([]byte(intJsonString), decoded))
......@@ -120,6 +121,27 @@ func TestWithdrawalNetworkInlineJSON(t *testing.T) {
encoded, err := json.Marshal(decoded)
require.NoError(t, err)
require.JSONEq(t, jsonString, string(encoded))
require.JSONEq(t, intJsonString, string(encoded))
})
}
func TestWithdrawalNetworkMarshalJSON(t *testing.T) {
type test struct {
Network WithdrawalNetwork
}
tests := []struct {
network WithdrawalNetwork
exp string
}{
{WithdrawalNetwork("local"), `{"Network":1}`},
{WithdrawalNetwork("remote"), `{"Network":0}`},
}
for _, tt := range tests {
t.Run(string(tt.network), func(t *testing.T) {
data, err := json.Marshal(test{tt.network})
require.NoError(t, err)
require.JSONEq(t, tt.exp, string(data))
})
}
}
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