Skip to content

Instantly share code, notes, and snippets.

@juanfranblanco
Last active July 1, 2021 08:55
Show Gist options
  • Save juanfranblanco/4cc998247aecd822d6088e382d94a6f1 to your computer and use it in GitHub Desktop.
Save juanfranblanco/4cc998247aecd822d6088e382d94a6f1 to your computer and use it in GitHub Desktop.
EIP1559 RLP Nethereum Signing test scenarios

EIP1559 RLP Nethereum Signing test scenarios

Private key: 0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7

Check out the RLP Debugger, pretty cool tool -> https://codechain-io.github.io/rlp-debugger/

Test scenarios RLP with no access lists

First RLP, used to sign Second RLP signed

(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

1559,0,3,4,3500,,10,

02cd820617800304820dac800a80c0 02f850820617800304820dac800a80c080a0de12484b58bd47130bf9964740b4d68e42bcbbbc39b2eed5b917f0ae66f5e630a01b0d7aa6a810d63c25c115ef217e37023bbe3146b9bb1fe580d004d6432f7f32


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

1559,2,3,4,3500,0x1ad91ee08f21be3de0ba2ba6918e714da6b45836,10,0x1232

02e3820617020304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a821232c0 02f866820617020304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a821232c080a0d5ee3f01ce51d2b2930b268361be6fe9fc542e09311336d335cc4658d7bd7128a0038501925930d090429373c7855220d33a6cb949ea3bea273edcd540271c59ce


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

0,0,0,0,0,,0,

02c98080808080808080c0 02f84c8080808080808080c001a001d4a14026b819394d91fef9336d00d3febed6fbe5d0a993c0d29a3b275c03b6a00cf6961f932346b5e6e5774c063e7a8794cd2dace75464d1fe5f38f3ba744cb5


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

2,0,3,4,3500,,10,

02cb02800304820dac800a80c0 02f84e02800304820dac800a80c001a046cfe7dde69e52b91eafd3b213e4547d9ff6294a5ad79383bdb347828fe20102a041e5ab79953b91967bf790a138d9c380d856e6d8b783f1c1751bc446610e6cc6


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

1559,0,3,0,3500,,0,0x1232

02cf820617800380820dac8080821232c0 02f852820617800380820dac8080821232c001a0ea5637f224ab5b53d4efff652631e42647f3e4a1c539a14864b788c5178ae186a0242e177e38763bf6a0c0c48e9c078814177286367767e09fb362ce49b3577bc3


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data) 1559,100,3,4,3500,0x1ad91ee08f21be3de0ba2ba6918e714da6b45836,10,0x1232

02e3820617640304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a821232c0 02f866820617640304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a821232c001a04e731e02022a10b97312998630d3dcaabda660e4a5f53d0fc1ebf4ba0cf8597fa01f4639e24823c565e3ac8e094e6eda571d1691022de83285925f9979b8ad7365


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data) 1559,2,3,4,3500,0x1ad91ee08f21be3de0ba2ba6918e714da6b45836,10,

02e1820617020304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a80c0 02f864820617020304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a80c080a02b7505766dabb65f8ef497955459f9ea43ff4a092153a8acb277321a80b784a8a0276140649dae47bbb8f6d8fdc3e0daddb58bba498aa4e0b8c547d0d8ebdbf9a5

Test scenarios RLP with access lists

First RLP, used to sign Second RLP signed

AccessLists For all test cases:

 var accessLists = new List<AccessListItem>();
            accessLists.Add(new AccessListItem("0x527306090abaB3A6e1400e9345bC60c78a8BEf57",
                new List<byte[]>
                {
                    "0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abab".HexToByteArray(),
                    "0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abac".HexToByteArray()
                }
            ));
            accessLists.Add(new AccessListItem("0x427306090abaB3A6e1400e9345bC60c78a8BEf5c",
                new List<byte[]>
                {
                    "0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaa".HexToByteArray(),
                    "0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad".HexToByteArray()
                }
            ));

(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

1559,2,3,4,3500,0x1ad91ee08f21be3de0ba2ba6918e714da6b45836,10,0x1232

02f8da820617020304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a821232f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad

02f9011d820617020304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a821232f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad80a0b46b5b81109a9f337e1520e8cc0bcf38a4d4e493e9db1001eab69272dccd9eb6a07779587f3f71b88cdb1d7f600c2217c8b0994d0fdc5b4ad2721b949dc76a522d


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

[0,0,0,0,0,,0, ]

02f8c08080808080808080f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad

02f901038080808080808080f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad80a0dfe419d097eb1eddcec5b4f22e15a77955049e35035b54f9485224efb1ac91bea03c0e9934078bb2e284ded87c7858fe73ebf3a1ee0433561c2ccd1328f29d1f7c

(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

1559,2,3,4,3500,0x1ad91ee08f21be3de0ba2ba6918e714da6b45836,10,

02f8d8820617020304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a80f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad 02f9011b820617020304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a80f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad80a08c7b1061785c2234a2d6f312c9849caef23d83bc9535f7f62a70484707df7c88a054c3c80a29fe315c7083109c017f936043da6b9decceea2702e285db040ce070


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

1559,100,3,4,3500,0x1ad91ee08f21be3de0ba2ba6918e714da6b45836,10,0x1232

02f8da820617640304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a821232f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad 02f9011d820617640304820dac941ad91ee08f21be3de0ba2ba6918e714da6b458360a821232f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad01a0e143b3ac02ba53b18267fa31f6daf330765eccea60832c44cd50d2b201864c78a063215db43ab8aadfc2b4163feec722c148208c5abf7b4e5f5faaf4a5172b7973


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

1559,0,3,0,3500,,0,0x1232

02f8c6820617800380820dac8080821232f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad 02f90109820617800380820dac8080821232f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad80a05162013f5dd5584e85004c8465f55cddb6d553270903fffb6dea7a45adbd1da4a00d28b6878d8d62dcc57a6d683f078991fa5a96ee129a15fb7e329917d930903b


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

1559,0,3,4,3500,,10,

02f8c4820617800304820dac800a80f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad

02f90107820617800304820dac800a80f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad80a06df9f35f3dc22cd50ed13fd14b5f486438ee8bdd5ab655d462c06017e007545ba07cf5ba481beee2fed39e42fb3c69aff83330b62a3566b0384131822c72a348df


(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas, ulong gasLimit, string receiverAddress, ulong amount, string data)

2,0,3,4,3500,,10,

02f8c202800304820dac800a80f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad

02f9010502800304820dac800a80f8b6f85994527306090abab3a6e1400e9345bc60c78a8bef57f842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3ababa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abacf85994427306090abab3a6e1400e9345bc60c78a8bef5cf842a03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaaa03fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad01a0ad0e12a167a39a6aaeb64713ee20a452aa949a9839689f4fd6d95f0143ad4786a03bafe00fd5f7ead7aefa15ccb6f4386d249a6b3a0dcc83914218290db6650366


RPC response

Transaction1559(1559, 6, 1, 1, 45000, "0x1ad91ee08f21be3de0ba2ba6918e714da6b45836", 10, "", accessLists);

{"jsonrpc":"2.0","id":1,"result":{"blockHash":null,"blockNumber":null,"from":"0x12890d2cce102216644c59dae5baed380d84830c","gas":"0xafc8","gasPrice":null,"maxFeePerGas":"0x1","maxPriorityFeePerGas":"0x1","hash":"0x60395a6f39c4cfbda12e66562d1dd095fe56e8d5290299c413df1fd911532258","input":"0x","nonce":"0x6","to":"0x1ad91ee08f21be3de0ba2ba6918e714da6b45836","transactionIndex":null,"value":"0xa","type":"0x2","accessList":[{"address":"0x527306090abab3a6e1400e9345bc60c78a8bef57","storageKeys":["0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abab","0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abac"]},{"address":"0x427306090abab3a6e1400e9345bc60c78a8bef5c","storageKeys":["0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaa","0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad"]}],"chainId":"0x617","v":"0x1","r":"0x6684429ffff68392317e630a1da3ebe5f2100fc779d15e2d78423019f9df5494","s":"0x7f1f9d27a0319dbb307040beb5ef7e30645b4082ccce0de907102e3cfdb2b04d"}}

Others

1559 (chain) nonce 0, 2000000000, 2000000014, 45000, "0x1ad91ee08f21be3de0ba2ba6918e714da6b45836", 10, "" 02f86c820617808477359400847735940e82afc8941ad91ee08f21be3de0ba2ba6918e714da6b458360a80c080a004825f75881efdd6b09943f368118c25728d6a9726eef26d0b64fb71d22f422ca018045cf6b4ea1d9ded43f5f190ef900ad0e47fd35f020cf3ca00e8d8c719a8a8

nonce 1

02f86c820617018477359400847735940e82afc8941ad91ee08f21be3de0ba2ba6918e714da6b458360a80c001a09388211ec4e48d6f4bdea91470669e05dc1ec8df3e0e31dd7f9238d3132c46b2a04d02de84f032f314503b1fc39a594205c5ae19492683ff13f76fa11189160160

nonce 2

02f86c820617028477359400847735940e82afc8941ad91ee08f21be3de0ba2ba6918e714da6b458360a80c001a04d1a096fbfc12d31ce7ab3c92b0c26ea88031fcd851eca91a7b79e12ea9f7805a06f4211a6fd52360f26ea652eae38166eafe593a8708d570891bbf9fd9993d99e

Tests in Nethereum

 public class EIP1559Test
   {


       [Theory]
       [InlineData(1559, 2, 3, 4, 3500, "0x1ad91ee08f21be3de0ba2ba6918e714da6b45836", 10, "")]
       [InlineData(1559, 2, 3, 4, 3500, "0x1ad91ee08f21be3de0ba2ba6918e714da6b45836", 10, "0x1232")]
       [InlineData(1559, 100, 3, 4, 3500, "0x1ad91ee08f21be3de0ba2ba6918e714da6b45836", 10, "0x1232")]
       [InlineData(1559, 0, 3, 0, 3500, null, 0, "0x1232")]
       [InlineData(1559, 0, 3, 4, 3500, null, 10, null)]
       [InlineData(2, 0, 3, 4, 3500, null, 10, null)]
       [InlineData(0, 0, 0, 0, 0, null, 0, null)]
       public void ShouldEncodeDecodeSignTransaction(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas,
           ulong gasLimit, string receiverAddress, ulong amount, string data)
       {
           var transaction1559 = new Transaction1559(chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, receiverAddress, amount, data, null);
           transaction1559.Sign(new EthECKey("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"));
           var encodedData = transaction1559.GetRLPEncodedRaw();
           var signedData = transaction1559.GetRLPEncoded();
           Debug.WriteLine(chainId + "," + nonce + "," + maxPriorityFeePerGas + "," + maxFeePerGas + "," + gasLimit + "," + receiverAddress + "," + amount + "," + data);
           Debug.WriteLine(encodedData.ToHex());
           Debug.WriteLine(signedData.ToHex());
           var decodedTransaction1559 = Transaction1559Encoder.Current.Decode(signedData);
           Assert.Equal(transaction1559.Amount, decodedTransaction1559.Amount);
           Assert.Equal(transaction1559.Nonce, decodedTransaction1559.Nonce);
           Assert.Equal(transaction1559.ChainId, decodedTransaction1559.ChainId);
           if (string.IsNullOrEmpty(transaction1559.Data))
           {
               Assert.Null(decodedTransaction1559.Data);
           }
           else
           {
               Assert.Equal(transaction1559.Data, decodedTransaction1559.Data);
           }

           Assert.Equal(transaction1559.GasLimit, decodedTransaction1559.GasLimit);
           Assert.Equal(transaction1559.MaxFeePerGas, decodedTransaction1559.MaxFeePerGas);
           Assert.Equal(transaction1559.MaxPriorityFeePerGas, decodedTransaction1559.MaxPriorityFeePerGas);

           if (string.IsNullOrEmpty(transaction1559.ReceiverAddress))
           {
               Assert.Null(decodedTransaction1559.ReceiverAddress);
           }
           else
           {
               Assert.Equal(transaction1559.ReceiverAddress, decodedTransaction1559.ReceiverAddress);
           }
   

           Assert.Equal(transaction1559.Signature.V.ToHex(), decodedTransaction1559.Signature.V.ToHex());
           Assert.Equal(transaction1559.Signature.R.ToHex(), decodedTransaction1559.Signature.R.ToHex());
           Assert.Equal(transaction1559.Signature.S.ToHex(), decodedTransaction1559.Signature.S.ToHex());

           Assert.True(decodedTransaction1559.VerifyTransaction());
           Assert.True(decodedTransaction1559.GetSenderAddress().IsTheSameAddress("0x12890D2cce102216644c59daE5baed380d84830c"));
       }

       [Theory]
       [InlineData(1559, 2, 3, 4, 3500, "0x1ad91ee08f21be3de0ba2ba6918e714da6b45836", 10, "")]
       [InlineData(1559, 2, 3, 4, 3500, "0x1ad91ee08f21be3de0ba2ba6918e714da6b45836", 10, "0x1232")]
       [InlineData(1559, 100, 3, 4, 3500, "0x1ad91ee08f21be3de0ba2ba6918e714da6b45836", 10, "0x1232")]
       [InlineData(1559, 0, 3, 0, 3500, null, 0, "0x1232")]
       [InlineData(1559, 0, 3, 4, 3500, null, 10, null)]
       [InlineData(2, 0, 3, 4, 3500, null, 10, null)]
       [InlineData(0, 0, 0, 0, 0, null, 0, null)]
       public void ShouldEncodeDecodeSignTransactionAccessLists(ulong chainId, ulong nonce, ulong maxPriorityFeePerGas, ulong maxFeePerGas,
          ulong gasLimit, string receiverAddress, ulong amount, string data)
       {

           var accessLists = new List<AccessListItem>();
           accessLists.Add(new AccessListItem("0x527306090abaB3A6e1400e9345bC60c78a8BEf57",
               new List<byte[]>
               {
                   "0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abab".HexToByteArray(),
                   "0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abac".HexToByteArray()
               }
           ));
           accessLists.Add(new AccessListItem("0x427306090abaB3A6e1400e9345bC60c78a8BEf5c",
               new List<byte[]>
               {
                   "0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abaa".HexToByteArray(),
                   "0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abad".HexToByteArray()
               }
           ));

           var transaction1559 = new Transaction1559(chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, receiverAddress, amount, data, accessLists);
           transaction1559.Sign(new EthECKey("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"));

           var encodedData = transaction1559.GetRLPEncodedRaw();
           var signedData = transaction1559.GetRLPEncoded();
           Debug.WriteLine(chainId + "," + nonce + "," + maxPriorityFeePerGas + "," + maxFeePerGas + "," + gasLimit + "," + receiverAddress + "," + amount + "," + data);
           Debug.WriteLine("");
           Debug.WriteLine(encodedData.ToHex());
           Debug.WriteLine(signedData.ToHex());
           var decodedTransaction1559 = Transaction1559Encoder.Current.Decode(signedData);
           Assert.Equal(transaction1559.Amount, decodedTransaction1559.Amount);
           Assert.Equal(transaction1559.Nonce, decodedTransaction1559.Nonce);
           Assert.Equal(transaction1559.ChainId, decodedTransaction1559.ChainId);
           if (string.IsNullOrEmpty(transaction1559.Data))
           {
               Assert.Null(decodedTransaction1559.Data);
           }
           else
           {
               Assert.Equal(transaction1559.Data, decodedTransaction1559.Data);
           }

           Assert.Equal(transaction1559.GasLimit, decodedTransaction1559.GasLimit);
           Assert.Equal(transaction1559.MaxFeePerGas, decodedTransaction1559.MaxFeePerGas);
           Assert.Equal(transaction1559.MaxPriorityFeePerGas, decodedTransaction1559.MaxPriorityFeePerGas);

           var decodedRlp = decodedTransaction1559.AccessList;

           Assert.True(accessLists[0].Address.IsTheSameAddress(decodedRlp[0].Address));
           Assert.Equal(accessLists[0].StorageKeys[0].ToHex(true), decodedRlp[0].StorageKeys[0].ToHex(true));
           Assert.Equal(accessLists[0].StorageKeys[1].ToHex(true), decodedRlp[0].StorageKeys[1].ToHex(true));
           Assert.True(accessLists[1].Address.IsTheSameAddress(decodedRlp[1].Address));
           Assert.Equal(accessLists[1].StorageKeys[0].ToHex(true), decodedRlp[1].StorageKeys[0].ToHex(true));
           Assert.Equal(accessLists[1].StorageKeys[1].ToHex(true), decodedRlp[1].StorageKeys[1].ToHex(true));

           if (string.IsNullOrEmpty(transaction1559.ReceiverAddress))
           {
               Assert.Null(decodedTransaction1559.ReceiverAddress);
           }
           else
           {
               Assert.Equal(transaction1559.ReceiverAddress, decodedTransaction1559.ReceiverAddress);
           }


           Assert.Equal(transaction1559.Signature.V.ToHex(), decodedTransaction1559.Signature.V.ToHex());
           Assert.Equal(transaction1559.Signature.R.ToHex(), decodedTransaction1559.Signature.R.ToHex());
           Assert.Equal(transaction1559.Signature.S.ToHex(), decodedTransaction1559.Signature.S.ToHex());
       }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment