package types

import (
	"encoding/hex"
	"encoding/json"
	"reflect"
	"testing"

	"github.com/ethereum/go-ethereum/rlp"
	"github.com/stretchr/testify/assert"
)

func TestRLPMarshalTransaction(t *testing.T) {

	table := []struct {
		json string
		rlp  string
	}{
		// legacy tx
		{
			json: `{"type":"0x0","hash":"0xdeffba5291f0d669ca63514f2f9c95fd313fcf6c2855ec929076225890113b59","nonce":"0x0","blockHash":"0xa751293043bba5353b0fca393820927ec9bc30a27916a085c92ba4e79f8152f7","transactionIndex":"0x0","from":"cfxtest:aaph8hphbv84fkn3bunm051aek68aua6wy0tg08xnd","to":null,"value":"0x0","gasPrice":"0x3b9aca00","gas":"0x6ed68","contractCreated":"cfxtest:aca514ancmbdu9u349u4m7d0u4jjdv83py3muarnv1","data":"0x608060405234801561001057600080fd5b50610544806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806328f7fd781461003b578063cf7bb3091461006b575b600080fd5b61005560048036038101906100509190610308565b61009b565b6040516100629190610432565b60405180910390f35b610085600480360381019061008091906102c3565b610115565b6040516100929190610432565b60405180910390f35b600084846040516100ad9291906103de565b60405180910390203373ffffffffffffffffffffffffffffffffffffffff167f14cb751d0950ff2788201931c45f715f7472443bc197311d9e3a7a0ba566b7e68787878760405161010194939291906103f7565b60405180910390a360019050949350505050565b600080600090505b838390508110156102225783838281811061013457fe5b905060200281019061014691906104a4565b8060000190610155919061044d565b6040516101639291906103de565b60405180910390203373ffffffffffffffffffffffffffffffffffffffff167f14cb751d0950ff2788201931c45f715f7472443bc197311d9e3a7a0ba566b7e68686858181106101af57fe5b90506020028101906101c191906104a4565b80600001906101d0919061044d565b8888878181106101dc57fe5b90506020028101906101ee91906104a4565b80602001906101fd919061044d565b60405161020d94939291906103f7565b60405180910390a3808060010191505061011d565b5082829050905092915050565b60008083601f84011261024157600080fd5b8235905067ffffffffffffffff81111561025a57600080fd5b60208301915083602082028301111561027257600080fd5b9250929050565b60008083601f84011261028b57600080fd5b8235905067ffffffffffffffff8111156102a457600080fd5b6020830191508360018202830111156102bc57600080fd5b9250929050565b600080602083850312156102d657600080fd5b600083013567ffffffffffffffff8111156102f057600080fd5b6102fc8582860161022f565b92509250509250929050565b6000806000806040858703121561031e57600080fd5b600085013567ffffffffffffffff81111561033857600080fd5b61034487828801610279565b9450945050602085013567ffffffffffffffff81111561036357600080fd5b61036f87828801610279565b925092505092959194509250565b600061038983856104c8565b93506103968385846104ee565b61039f836104fd565b840190509392505050565b60006103b683856104d9565b93506103c38385846104ee565b82840190509392505050565b6103d8816104e4565b82525050565b60006103eb8284866103aa565b91508190509392505050565b6000604082019050818103600083015261041281868861037d565b9050818103602083015261042781848661037d565b905095945050505050565b600060208201905061044760008301846103cf565b92915050565b6000808335600160200384360303811261046657600080fd5b80840192508235915067ffffffffffffffff82111561048457600080fd5b60208301925060018202360383131561049c57600080fd5b509250929050565b6000823560016040038336030381126104bc57600080fd5b80830191505092915050565b600082825260208201905092915050565b600081905092915050565b6000819050919050565b82818337600083830152505050565b6000601f19601f830116905091905056fea26469706673582212200aab70e63ece6dc222afcf381fec642c6d414adf33cf0ed6da53680bd904f5ac64736f6c63430007040033","storageLimit":"0x466","epochHeight":"0x43e","chainId":"0x1","status":"0x0","v":"0x0","r":"0x4b0551c1db7ec8ea089f15e679cf0ec3ba15c638b8b3f71ce8df5e35f29f6c9f","s":"0x7c7f2130c26c31f744092a58ea3daac826695a9aef45ec6fad38b9a0c2882a23"}`,
			rlp:  `f90c27b84230786465666662613532393166306436363963613633353134663266396339356664333133666366366332383535656339323930373632323538393031313362353980b84230786137353132393330343362626135333533623066636133393338323039323765633962633330613237393136613038356339326261346537396638313532663780f83987636678746573748475736572a200000c071e070c0701111e1a05090b1901100b0a161b170004091c1e0010001c121488160f06161e130b03c080843b9aca008306ed68f83d876366787465737488636f6e7472616374a20002001b171a000b020a0103101f10191a1f101a0a1d0316101a080803111e190c1488190a10000d0b1117b90aca307836303830363034303532333438303135363130303130353736303030383066643562353036313035343438303631303032303630303033393630303066336665363038303630343035323334383031353631303031303537363030303830666435623530363030343336313036313030333635373630303033353630653031633830363332386637666437383134363130303362353738303633636637626233303931343631303036623537356236303030383066643562363130303535363030343830333630333831303139303631303035303931393036313033303835363562363130303962353635623630343035313631303036323931393036313034333235363562363034303531383039313033393066333562363130303835363030343830333630333831303139303631303038303931393036313032633335363562363130313135353635623630343035313631303039323931393036313034333235363562363034303531383039313033393066333562363030303834383436303430353136313030616439323931393036313033646535363562363034303531383039313033393032303333373366666666666666666666666666666666666666666666666666666666666666666666666666666666313637663134636237353164303935306666323738383230313933316334356637313566373437323434336263313937333131643965336137613062613536366237653638373837383738373630343035313631303130313934393339323931393036313033663735363562363034303531383039313033393061333630303139303530393439333530353035303530353635623630303038303630303039303530356238333833393035303831313031353631303232323537383338333832383138313130363130313334353766653562393035303630323030323831303139303631303134363931393036313034613435363562383036303030303139303631303135353931393036313034346435363562363034303531363130313633393239313930363130336465353635623630343035313830393130333930323033333733666666666666666666666666666666666666666666666666666666666666666666666666666666663136376631346362373531643039353066663237383832303139333163343566373135663734373234343362633139373331316439653361376130626135363662376536383638363835383138313130363130316166353766653562393035303630323030323831303139303631303163313931393036313034613435363562383036303030303139303631303164303931393036313034346435363562383838383837383138313130363130316463353766653562393035303630323030323831303139303631303165653931393036313034613435363562383036303230303139303631303166643931393036313034346435363562363034303531363130323064393439333932393139303631303366373536356236303430353138303931303339306133383038303630303130313931353035303631303131643536356235303832383239303530393035303932393135303530353635623630303038303833363031663834303131323631303234313537363030303830666435623832333539303530363766666666666666666666666666666666383131313135363130323561353736303030383066643562363032303833303139313530383336303230383230323833303131313135363130323732353736303030383066643562393235303932393035303536356236303030383038333630316638343031313236313032386235373630303038306664356238323335393035303637666666666666666666666666666666663831313131353631303261343537363030303830666435623630323038333031393135303833363030313832303238333031313131353631303262633537363030303830666435623932353039323930353035363562363030303830363032303833383530333132313536313032643635373630303038306664356236303030383330313335363766666666666666666666666666666666383131313135363130326630353736303030383066643562363130326663383538323836303136313032326635363562393235303932353035303932353039323930353035363562363030303830363030303830363034303835383730333132313536313033316535373630303038306664356236303030383530313335363766666666666666666666666666666666383131313135363130333338353736303030383066643562363130333434383738323838303136313032373935363562393435303934353035303630323038353031333536376666666666666666666666666666666638313131313536313033363335373630303038306664356236313033366638373832383830313631303237393536356239323530393235303530393239353931393435303932353035363562363030303631303338393833383536313034633835363562393335303631303339363833383538343631303465653536356236313033396638333631303466643536356238343031393035303933393235303530353035363562363030303631303362363833383536313034643935363562393335303631303363333833383538343631303465653536356238323834303139303530393339323530353035303536356236313033643838313631303465343536356238323532353035303536356236303030363130336562383238343836363130336161353635623931353038313930353039333932353035303530353635623630303036303430383230313930353038313831303336303030383330313532363130343132383138363838363130333764353635623930353038313831303336303230383330313532363130343237383138343836363130333764353635623930353039353934353035303530353035303536356236303030363032303832303139303530363130343437363030303833303138343631303363663536356239323931353035303536356236303030383038333335363030313630323030333834333630333033383131323631303436363537363030303830666435623830383430313932353038323335393135303637666666666666666666666666666666663832313131353631303438343537363030303830666435623630323038333031393235303630303138323032333630333833313331353631303439633537363030303830666435623530393235303932393035303536356236303030383233353630303136303430303338333336303330333831313236313034626335373630303038306664356238303833303139313530353039323931353035303536356236303030383238323532363032303832303139303530393239313530353035363562363030303831393035303932393135303530353635623630303038313930353039313930353035363562383238313833333736303030383338333031353235303530353035363562363030303630316631393630316638333031313639303530393139303530353666656132363436393730363637333538323231323230306161623730653633656365366463323232616663663338316665633634326336643431346164663333636630656436646135333638306264393034663561633634373336663663363334333030303730343030333382046682043e018080a04b0551c1db7ec8ea089f15e679cf0ec3ba15c638b8b3f71ce8df5e35f29f6c9fa07c7f2130c26c31f744092a58ea3daac826695a9aef45ec6fad38b9a0c2882a23`,
		},
		{
			json: `{"type":"0x0","hash":"0x4016c5b1675182700ef67b9df90c13ddf2e774b12385af63ba43576039b13f8a","nonce":"0x0","blockHash":"0xce70d3387731e0d09605c37c322070ba30223b327b8790b15086847241cb857d","transactionIndex":"0x0","from":"cfx:aam9edem02j9tmzavu81y4g0ygy06cyeg2vx3zwe8y","to":"cfx:acb59fk6vryh8dj5vyvehj9apzhpd72rdpwsc651kz","value":"0x0","gasPrice":"0x1","gas":"0x4c4b40","contractCreated":null,"data":"0xfebe49090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000162788589c8e386863f217faef78840919fb2854","storageLimit":"0x40","epochHeight":"0x5","chainId":"0x405","status":"0x0","v":"0x0","r":"0x7c15d3f0e517a66ad96a79cfd24b00439de725d9cbbcb8a1d0107cd5c16c8751","s":"0x27a0faab73d4ab512fa97d9e52ef3b3d2bea2a39d58c8d3d65dac59abbe6fee5"}`,
			rlp:  `f901d7b84230783430313663356231363735313832373030656636376239646639306331336464663265373734623132333835616636336261343335373630333962313366386180b84230786365373064333338373733316530643039363035633337633332323037306261333032323362333237623837393062313530383638343732343163623835376480f5836366788475736572a200000a1f0403040a1618081f0f0a150011101e17141a0616140614161c0214040618881113191512041e14f8398363667888636f6e7472616374a20002011b1f05091c110d14071e03081b1114110407081f000c15070c031d180d030c88120e021c1b1709158001834c4b40c0b88a30786665626534393039303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303136323738383538396338653338363836336632313766616566373838343039313966623238353440058204058080a07c15d3f0e517a66ad96a79cfd24b00439de725d9cbbcb8a1d0107cd5c16c8751a027a0faab73d4ab512fa97d9e52ef3b3d2bea2a39d58c8d3d65dac59abbe6fee5`,
		},
		// access list tx
		{
			json: `{"accessList":[{"address":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","storageKeys":["0x0000000000000000000000000000000000000000000000000000000000000000"]}],"type":"0x1","hash":"0x79bc3f80eebc0c367c0d8749eb5134c6c0523477b92cbde9d2b36b9f1402a216","nonce":"0x11","blockHash":"0x7fab5518a46d13a4d8b5c32d953872f41225a6bd5876781e97b094ef3ff03d4f","transactionIndex":"0x0","from":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","to":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","value":"0x0","gasPrice":"0x1","gas":"0x62d4","contractCreated":null,"data":"0x","storageLimit":"0x0","epochHeight":"0x14e991","chainId":"0x22b8","status":"0x0","v":"0x0","r":"0x56f0775d2293088208e0cb8d39f53a632014f9516f233998cd0b0f08fd8dc48b","s":"0x6a17392338f6acc8df76eaabb3ab8ca876ea965cec40d4ddfdf14fbc0dd7df41"}`,
			rlp:  `8363667801f901b801b84230783739626333663830656562633063333637633064383734396562353133346336633035323334373762393263626465396432623336623966313430326132313611b84230783766616235353138613436643133613464386235633332643935333837326634313232356136626435383736373831653937623039346566336666303364346680f839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1df839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1d808262d401c0823078808314e9918222b880f85ff85df839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1de1a0000000000000000000000000000000000000000000000000000000000000000080a056f0775d2293088208e0cb8d39f53a632014f9516f233998cd0b0f08fd8dc48ba06a17392338f6acc8df76eaabb3ab8ca876ea965cec40d4ddfdf14fbc0dd7df4180`,
		},
		// dynamic tx
		{
			json: `{"accessList":[{"address":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","storageKeys":["0x0000000000000000000000000000000000000000000000000000000000000000"]}],"type":"0x2","hash":"0x79bc3f80eebc0c367c0d8749eb5134c6c0523477b92cbde9d2b36b9f1402a216","nonce":"0x11","blockHash":"0x7fab5518a46d13a4d8b5c32d953872f41225a6bd5876781e97b094ef3ff03d4f","transactionIndex":"0x0","from":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","to":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","value":"0x0","gasPrice":"0x0","gas":"0x62d4","contractCreated":null,"data":"0x","storageLimit":"0x0","epochHeight":"0x14e991","chainId":"0x22b8","status":"0x0","maxPriorityFeePerGas":"0x779b4daa","maxFeePerGas":"0x779b4daa","v":"0x0","r":"0x56f0775d2293088208e0cb8d39f53a632014f9516f233998cd0b0f08fd8dc48b","s":"0x6a17392338f6acc8df76eaabb3ab8ca876ea965cec40d4ddfdf14fbc0dd7df41"}`,
			rlp:  `8363667802f901c202b84230783739626333663830656562633063333637633064383734396562353133346336633035323334373762393263626465396432623336623966313430326132313611b84230783766616235353138613436643133613464386235633332643935333837326634313232356136626435383736373831653937623039346566336666303364346680f839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1df839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1d808262d480c0823078808314e9918222b880f85ff85df839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1de1a0000000000000000000000000000000000000000000000000000000000000000084779b4daa84779b4daa80a056f0775d2293088208e0cb8d39f53a632014f9516f233998cd0b0f08fd8dc48ba06a17392338f6acc8df76eaabb3ab8ca876ea965cec40d4ddfdf14fbc0dd7df4180`,
		},
	}

	t.Run("Encode", func(t *testing.T) {
		for _, item := range table {
			// Encode
			var tx Transaction
			err := json.Unmarshal([]byte(item.json), &tx)
			assert.NoError(t, err)

			dBytes, err := rlp.EncodeToBytes(tx)
			assert.NoError(t, err)

			assert.Equal(t, item.rlp, hex.EncodeToString(dBytes))
		}
	})

	t.Run("Decode", func(t *testing.T) {
		for _, item := range table {
			// Decode
			var tx2 Transaction
			dBytes, err := hex.DecodeString(item.rlp)
			assert.NoError(t, err)

			err = rlp.DecodeBytes(dBytes, &tx2)
			assert.NoError(t, err)

			jBytes2, err := json.Marshal(tx2)
			assert.NoError(t, err)

			assert.Equal(t, item.json, string(jBytes2))
		}
	})
}

func TestRLPMarshalTransactionReceipt(t *testing.T) {

	table := []struct {
		json string
		rlp  string
	}{
		// legacy
		{
			json: `{"type":"0x0","transactionHash":"0xdeffba5291f0d669ca63514f2f9c95fd313fcf6c2855ec929076225890113b59","index":"0x0","blockHash":"0xa751293043bba5353b0fca393820927ec9bc30a27916a085c92ba4e79f8152f7","epochNumber":"0x441","from":"cfxtest:aaph8hphbv84fkn3bunm051aek68aua6wy0tg08xnd","to":null,"gasUsed":"0x64c30","gasFee":"0x1775ddcfde000","effectiveGasPrice":null,"contractCreated":"cfxtest:aca514ancmbdu9u349u4m7d0u4jjdv83py3muarnv1","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","stateRoot":"0x3f57ef68b851da591aac50f1cbdf369d87a2e3b66d7679a00678fb5fcd02653a","outcomeStatus":"0x0","txExecErrorMsg":null,"gasCoveredBySponsor":false,"storageCoveredBySponsor":false,"storageCollateralized":"0x400","storageReleased":[]}`,
			rlp:  `f90365b84230786465666662613532393166306436363963613633353134663266396339356664333133666366366332383535656339323930373632323538393031313362353980b842307861373531323933303433626261353335336230666361333933383230393237656339626333306132373931366130383563393262613465373966383135326637820441f83987636678746573748475736572a200000c071e070c0701111e1a05090b1901100b0a161b170004091c1e0010001c121488160f06161e130b03c083064c308701775ddcfde000f83d876366787465737488636f6e7472616374a20002001b171a000b020a0103101f10191a1f101a0a1d0316101a080803111e190c1488190a10000d0b1117c0b9020230783030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030b84230783366353765663638623835316461353931616163353066316362646633363964383761326533623636643736373961303036373866623566636430323635336180808080820400c0`,
		},
		{
			json: `{"type":"0x0","transactionHash":"0xa45f5101687f1cc11ea8ea56eab670cff670c55c84c7feb06ed33b7840346c60","index":"0x1","blockHash":"0x25fd857127dbef9e9a4f851ade9b11ac1cb22967266d915fe00f61ec1e356f54","epochNumber":"0xfce4df","from":"cfx:aarh9m8vs8ecrhmw76efb61a5w9yjwyyapz8yj2evb","to":"cfx:acbcnsptvcgggjwb7u8gbprffacx7657k67j8taaxg","gasUsed":"0x13b3a","gasFee":"0x13b3a","effectiveGasPrice":null,"contractCreated":null,"logs":[{"address":"cfx:acc8ya1f2a2bfphxg5ax7a8h29k47d5xsebxfj24nd","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000008225b98f888c632241ec3c60b1a528053ef37d4f","0x0000000000000000000000001a7fabd17788269d52ef0850f2e0dcbf444a9403"],"data":"0x00000000000000000000000000000000000000000000000016b276f7e4180350","blockHash":"0x25fd857127dbef9e9a4f851ade9b11ac1cb22967266d915fe00f61ec1e356f54","epochNumber":"0xfce4df","transactionHash":"0xa45f5101687f1cc11ea8ea56eab670cff670c55c84c7feb06ed33b7840346c60","transactionIndex":"0x1","logIndex":"0x0","transactionLogIndex":"0x0"},{"address":"cfx:acbcnsptvcgggjwb7u8gbprffacx7657k67j8taaxg","topics":["0x90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15","0x0000000000000000000000001a7fabd17788269d52ef0850f2e0dcbf444a9403","0x0000000000000000000000000000000000000000000000000000000000000001"],"data":"0x0000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x25fd857127dbef9e9a4f851ade9b11ac1cb22967266d915fe00f61ec1e356f54","epochNumber":"0xfce4df","transactionHash":"0xa45f5101687f1cc11ea8ea56eab670cff670c55c84c7feb06ed33b7840346c60","transactionIndex":"0x1","logIndex":"0x1","transactionLogIndex":"0x1"}],"logsBloom":"0x00000000000000400000000000000000000000000400000000000000000010000000000000800000000000000000000008000000000000000000000000040000000000000000000000000008000000000000000000040000000000000000000000000000000000200000000000000000000000000000000000000010000100000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000010001000000000000000000000000000000000002000000000000000000040000000000000000000000000000000040000000000000000400010000000000000000000000400000200000000000000000","stateRoot":"0x46347c46f62b53144431cfd6d1e5af9bdf2d2f0ed13b4e68f96cba6cf3839ec0","outcomeStatus":"0x0","txExecErrorMsg":null,"gasCoveredBySponsor":true,"storageCoveredBySponsor":true,"storageCollateralized":"0x0","storageReleased":[]}`,
			rlp:  `f906d9b84230786134356635313031363837663163633131656138656135366561623637306366663637306335356338346337666562303665643333623738343033343663363001b84230783235666438353731323764626566396539613466383531616465396231316163316362323239363732363664393135666530306636316563316533353666353483fce4dff5836366788475736572a200000d071f0a1e110e1e04020d070a121d1c0405011c17001b121f1408121414000c88151e140818041101f8398363667888636f6e7472616374a2000201020b0e0c0f11020606060812011d101e06010c0d05050002131d1c1b1d091c881d081e0f0000130683013b3a83013b3ac0f90380f901bdf8398363667888636f6e7472616374a20002021e1400170518001801050c0713061b00131d001e07181f091a1d031b130e048801130508181a0b03f8ccb842307864646632353261643162653263383962363963326230363866633337386461613935326261376631363363346131313632386635356134646635323362336566b842307830303030303030303030303030303030303030303030303038323235623938663838386336333232343165633363363062316135323830353365663337643466b842307830303030303030303030303030303030303030303030303031613766616264313737383832363964353265663038353066326530646362663434346139343033a000000000000000000000000000000000000000000000000016b276f7e4180350b842307832356664383537313237646265663965396134663835316164653962313161633163623232393637323636643931356665303066363165633165333536663534c483fce4dfb842307861343566353130313638376631636331316561386561353665616236373063666636373063353563383463376665623036656433336237383430333436633630c101c180c180f901bdf8398363667888636f6e7472616374a2000201020b0e0c0f11020606060812011d101e06010c0d05050002131d1c1b1d091c881d081e0f00001306f8ccb842307839303839303830396336353466313164366537326132386661363031343937373061306431316563366339323331396436636562326262306134656131613135b842307830303030303030303030303030303030303030303030303031613766616264313737383832363964353265663038353066326530646362663434346139343033b842307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303031a00000000000000000000000000000000000000000000000000000000000000000b842307832356664383537313237646265663965396134663835316164653962313161633163623232393637323636643931356665303066363165633165333536663534c483fce4dfb842307861343566353130313638376631636331316561386561353665616236373063666636373063353563383463376665623036656433336237383430333436633630c101c101c101b9020230783030303030303030303030303030343030303030303030303030303030303030303030303030303030343030303030303030303030303030303030303130303030303030303030303030383030303030303030303030303030303030303030303038303030303030303030303030303030303030303030303030303430303030303030303030303030303030303030303030303030303038303030303030303030303030303030303030303430303030303030303030303030303030303030303030303030303030303030303030323030303030303030303030303030303030303030303030303030303030303030303030303030303130303030313030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303038303030303030303030303030303030303030303030303030303130303031303030303030303030303030303030303030303030303030303030303030303030303032303030303030303030303030303030303030303430303030303030303030303030303030303030303030303030303030303030303430303030303030303030303030303030343030303130303030303030303030303030303030303030303030343030303030323030303030303030303030303030303030b8423078343633343763343666363262353331343434333163666436643165356166396264663264326630656431336234653638663936636261366366333833396563308080010180c0`,
		},
		{
			json: `{"type":"0x0","transactionHash":"0xa2c678cc97e07ce060b71f87ac65e68d482abf8e1a93b7d1bc425504c4584ca7","index":"0x1","blockHash":"0x935bc7ebab4e6256ade6327682de8bee6b15dcee5c83f7772ae6a945510fe940","epochNumber":"0xf7cf0d","from":"cfx:aaspca00u76ew2eharzsy355svm3t6yw4pxsyu7vka","to":"cfx:acam64yj323zd4t1fhybxh3jsg7hu4012yz9kakxs9","gasUsed":"0x22144","gasFee":"0xd4fe90","effectiveGasPrice":null,"contractCreated":null,"logs":[{"address":"cfx:acg158kvr8zanb1bs048ryb6rtrhr283ma70vz70tx","topics":["0x2fe5be0146f74c5bce36c0b80911af6c7d86ff27e89d5cfa61fc681327954e5d","0x00000000000000000000000080ae6a88ce3351e9f729e8199f2871ba786ad7c5","0x0000000000000000000000008d545118d91c027c805c552f63a5c00a20ae6aca"],"data":"0x00000000000000000000000000000000000000000000003b16c9e8eeb7c800000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},{"address":"cfx:acg158kvr8zanb1bs048ryb6rtrhr283ma70vz70tx","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000008d545118d91c027c805c552f63a5c00a20ae6aca"],"data":"0x00000000000000000000000000000000000000000000003b16c9e8eeb7c80000"},{"address":"cfx:acg158kvr8zanb1bs048ryb6rtrhr283ma70vz70tx","topics":["0x68051bc50b1ef1654bf1e6204b5f8fa9badcd038e00fa5b43f21f898fc2728ca","0x0000000000000000000000008d545118d91c027c805c552f63a5c00a20ae6aca","0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"],"data":"0x00000000000000000000000000000000000000000000003b16c9e8eeb7c80000"},{"address":"cfx:acf2rcsh8payyxpg6xj7b0ztswwh81ute60tsw35j7","topics":["0x06b541ddaa720db2b10a4d0cdac39b8d360425fc073085fac19bc82614677987","0x0000000000000000000000008d545118d91c027c805c552f63a5c00a20ae6aca","0x0000000000000000000000008d545118d91c027c805c552f63a5c00a20ae6aca","0x0000000000000000000000001cc102d68778496087036aea677b745597f292d3"],"data":"0x000000000000000000000000000000000000000000000019ceb8990635656bbf0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},{"address":"cfx:acf2rcsh8payyxpg6xj7b0ztswwh81ute60tsw35j7","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000008d545118d91c027c805c552f63a5c00a20ae6aca","0x0000000000000000000000001cc102d68778496087036aea677b745597f292d3"],"data":"0x000000000000000000000000000000000000000000000019ceb8990635656bbf"},{"address":"cfx:acgzjyj25esae9eanvmw827f2afcbnxm3jr3784tyu","topics":["0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1"],"data":"0x000000000000000000000000000000000000000000003a4a9c46eba30a4fb89e00000000000000000000000000000000000000000000854b7ce25c8407e77655"},{"address":"cfx:acgzjyj25esae9eanvmw827f2afcbnxm3jr3784tyu","topics":["0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822","0x00000000000000000000000080ae6a88ce3351e9f729e8199f2871ba786ad7c5","0x0000000000000000000000001cc102d68778496087036aea677b745597f292d3"],"data":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003b16c9e8eeb7c80000000000000000000000000000000000000000000000000019ceb8990635656bbf0000000000000000000000000000000000000000000000000000000000000000"}],"logsBloom":"0x0020000000000000000000008000000000000808000000000000000000000000804000000000200040080000009000000000000000000000000000000008000000000000000010000000000a00000020000000000000000000000000000000000000000002004000000000000000080004000040000000000000001000000000000008000020000000001100000002000000000000000018000000400000000000000000012000000000000000000000000000000000000000000000000000000000000200000010000004000000000000000000000000100000a000000020000000000000000400000000000000000000000000100000000000000000040000","stateRoot":"0x2b35e444ba6118f85447efc1c504b3526229c99451fd172ae35a49fe5d7127bd","outcomeStatus":"0x0","txExecErrorMsg":null,"gasCoveredBySponsor":true,"storageCoveredBySponsor":true,"storageCollateralized":"0x0","storageReleased":[]}`,
			rlp:  `f90cfeb84230786132633637386363393765303763653036306237316638376163363565363864343832616266386531613933623764316263343235353034633435383463613701b84230783933356263376562616234653632353661646536333237363832646538626565366231356463656535633833663737373261653661393435353130666539343083f7cf0df5836366788475736572a200000e0c02001616101d1c0412180407000d150e14191b1b0e110a190f1c14121a0c88130e14101d110900f8398363667888636f6e7472616374a20002000a1c1a140819181915031a0f1705071401130719080e061d07101a1617181488151f090009130e1f8302214483d4fe90c0f909a5f901b1f8398363667888636f6e7472616374a2000206171b1e09110d1e15000b0117010e161a1e0d14011c0d0f0d070d181e190a00881d1611151d160f13f8ccb842307832666535626530313436663734633562636533366330623830393131616636633764383666663237653839643563666136316663363831333237393534653564b842307830303030303030303030303030303030303030303030303038306165366138386365333335316539663732396538313939663238373162613738366164376335b842307830303030303030303030303030303030303030303030303038643534353131386439316330323763383035633535326636336135633030613230616536616361b8a000000000000000000000000000000000000000000000003b16c9e8eeb7c80000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080c080c0c0c0f90130f8398363667888636f6e7472616374a2000206171b1e09110d1e15000b0117010e161a1e0d14011c0d0f0d070d181e190a00881d1611151d160f13f8ccb842307864646632353261643162653263383962363963326230363866633337386461613935326261376631363363346131313632386635356134646635323362336566b842307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030b842307830303030303030303030303030303030303030303030303038643534353131386439316330323763383035633535326636336135633030613230616536616361a000000000000000000000000000000000000000000000003b16c9e8eeb7c8000080c080c0c0c0f90130f8398363667888636f6e7472616374a2000206171b1e09110d1e15000b0117010e161a1e0d14011c0d0f0d070d181e190a00881d1611151d160f13f8ccb842307836383035316263353062316566313635346266316536323034623566386661396261646364303338653030666135623433663231663839386663323732386361b842307830303030303030303030303030303030303030303030303038643534353131386439316330323763383035633535326636336135633030613230616536616361b842307863356432343630313836663732333363393237653764623264636337303363306535303062363533636138323237336237626661643830343564383561343730a000000000000000000000000000000000000000000000003b16c9e8eeb7c8000080c080c0c0c0f901f6f8398363667888636f6e7472616374a2000205180d020e071e0c001414130c061c13081d0116150f0e1212071e17100f041c88160f0e12191b081df90110b842307830366235343164646161373230646232623130613464306364616333396238643336303432356663303733303835666163313962633832363134363737393837b842307830303030303030303030303030303030303030303030303038643534353131386439316330323763383035633535326636336135633030613230616536616361b842307830303030303030303030303030303030303030303030303038643534353131386439316330323763383035633535326636336135633030613230616536616361b842307830303030303030303030303030303030303030303030303031636331303264363837373834393630383730333661656136373762373435353937663239326433b8a0000000000000000000000000000000000000000000000019ceb8990635656bbf000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080c080c0c0c0f90130f8398363667888636f6e7472616374a2000205180d020e071e0c001414130c061c13081d0116150f0e1212071e17100f041c88160f0e12191b081df8ccb842307864646632353261643162653263383962363963326230363866633337386461613935326261376631363363346131313632386635356134646635323362336566b842307830303030303030303030303030303030303030303030303038643534353131386439316330323763383035633535326636336135633030613230616536616361b842307830303030303030303030303030303030303030303030303031636331303264363837373834393630383730333661656136373762373435353937663239326433a0000000000000000000000000000000000000000000000019ceb8990635656bbf80c080c0c0c0f8c9f8398363667888636f6e7472616374a200020615081408181b040e00041f04000b110a121e181d0518000502010b130a1908880d191d1e1a0f1410f844b842307831633431316539613936653037313234316332663231663737323662313761653839653363616234633738626535306530363262303361396666666262616431b840000000000000000000000000000000000000000000003a4a9c46eba30a4fb89e00000000000000000000000000000000000000000000854b7ce25c8407e7765580c080c0c0c0f90191f8398363667888636f6e7472616374a200020615081408181b040e00041f04000b110a121e181d0518000502010b130a1908880d191d1e1a0f1410f8ccb842307864373861643935666134366339393462363535316430646138356663323735666536313363653337363537666238643565336431333038343031353964383232b842307830303030303030303030303030303030303030303030303038306165366138386365333335316539663732396538313939663238373162613738366164376335b842307830303030303030303030303030303030303030303030303031636331303264363837373834393630383730333661656136373762373435353937663239326433b880000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003b16c9e8eeb7c80000000000000000000000000000000000000000000000000019ceb8990635656bbf000000000000000000000000000000000000000000000000000000000000000080c080c0c0c0b9020230783030323030303030303030303030303030303030303030303830303030303030303030303038303830303030303030303030303030303030303030303030303038303430303030303030303032303030343030383030303030303930303030303030303030303030303030303030303030303030303030303030303830303030303030303030303030303030313030303030303030303061303030303030323030303030303030303030303030303030303030303030303030303030303030303030303030303030303230303430303030303030303030303030303030383030303430303030343030303030303030303030303030303130303030303030303030303030303830303030323030303030303030303131303030303030303230303030303030303030303030303030313830303030303034303030303030303030303030303030303030313230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303032303030303030313030303030303430303030303030303030303030303030303030303030303031303030303061303030303030303230303030303030303030303030303030343030303030303030303030303030303030303030303030303030313030303030303030303030303030303030303430303030b8423078326233356534343462613631313866383534343765666331633530346233353236323239633939343531666431373261653335613439666535643731323762648080010180c0`,
		},
		// access list
		{
			json: `{"type":"0x1","transactionHash":"0x79bc3f80eebc0c367c0d8749eb5134c6c0523477b92cbde9d2b36b9f1402a216","index":"0x0","blockHash":"0x7fab5518a46d13a4d8b5c32d953872f41225a6bd5876781e97b094ef3ff03d4f","epochNumber":"0x14e997","from":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","to":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","gasUsed":"0x62d4","accumulatedGasUsed":"0x0","gasFee":"0x2e2c805764c8","effectiveGasPrice":"0x779b4daa","contractCreated":null,"logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","stateRoot":"0xbc206a33f1918d12fb9905fd99fc06dfaf49db0fdf70e9eb18b053915345e18c","outcomeStatus":"0x0","txExecErrorMsg":null,"gasCoveredBySponsor":false,"storageCoveredBySponsor":false,"storageCollateralized":"0x0","storageReleased":[],"space":"","burntGasFee":"0xb814ec1a400"}`,
			rlp:  `8363667801f9036d01b84230783739626333663830656562633063333637633064383734396562353133346336633035323334373762393263626465396432623336623966313430326132313680b8423078376661623535313861343664313361346438623563333264393533383732663431323235613662643538373637383165393762303934656633666630336434668314e997f839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1df839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1d8262d480862e2c805764c884779b4daac0c0b9020230783030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030b8423078626332303661333366313931386431326662393930356664393966633036646661663439646230666466373065396562313862303533393135333435653138638080808080c080860b814ec1a400`,
		},
		// dynamic
		{
			json: `{"type":"0x2","transactionHash":"0x79bc3f80eebc0c367c0d8749eb5134c6c0523477b92cbde9d2b36b9f1402a216","index":"0x0","blockHash":"0x7fab5518a46d13a4d8b5c32d953872f41225a6bd5876781e97b094ef3ff03d4f","epochNumber":"0x14e997","from":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","to":"net8888:aamxnf2v91t8e9dabh5d3humnyxp28hrju94f55s67","gasUsed":"0x62d4","accumulatedGasUsed":"0x0","gasFee":"0x2e2c805764c8","effectiveGasPrice":"0x779b4daa","contractCreated":null,"logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","stateRoot":"0xbc206a33f1918d12fb9905fd99fc06dfaf49db0fdf70e9eb18b053915345e18c","outcomeStatus":"0x0","txExecErrorMsg":null,"gasCoveredBySponsor":false,"storageCoveredBySponsor":false,"storageCollateralized":"0x0","storageReleased":[],"space":"","burntGasFee":"0xb814ec1a400"}`,
			rlp:  `8363667802f9036d02b84230783739626333663830656562633063333637633064383734396562353133346336633035323334373762393263626465396432623336623966313430326132313680b8423078376661623535313861343664313361346438623563333264393533383732663431323235613662643538373637383165393762303934656633666630336434668314e997f839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1df839876e6574383838388475736572a200000a130b0518111f170f1e041f030001071b031907100a0b14130c181e070d0810881f1a051b1b0e1c1d8262d480862e2c805764c884779b4daac0c0b9020230783030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030b8423078626332303661333366313931386431326662393930356664393966633036646661663439646230666466373065396562313862303533393135333435653138638080808080c080860b814ec1a400`,
		},
	}

	t.Run("Encode", func(t *testing.T) {
		for _, item := range table {
			// Encode
			var tx TransactionReceipt
			err := json.Unmarshal([]byte(item.json), &tx)
			assert.NoError(t, err)

			dBytes, err := rlp.EncodeToBytes(tx)
			assert.NoError(t, err)

			assert.Equal(t, item.rlp, hex.EncodeToString(dBytes))
		}
	})

	t.Run("Decode", func(t *testing.T) {
		for _, item := range table {
			// Decode
			var tx2 TransactionReceipt
			dBytes, err := hex.DecodeString(item.rlp)
			assert.NoError(t, err)

			err = rlp.DecodeBytes(dBytes, &tx2)
			assert.NoError(t, err)

			jBytes2, err := json.Marshal(tx2)
			assert.NoError(t, err)

			assert.Equal(t, item.json, string(jBytes2))
		}
	})
}

func TestJsonTransaction(t *testing.T) {
	table := []string{
		`{"accessList":[],"type":"0x2","hash":"0x1b6a88dc91c1870f05242ee2121c36a9a16a736b510634f1c664bcd2cc02909b","nonce":"0x1","blockHash":"0x08659936ca25de4ac0e50555918941f45dbb9de8d867aa2ae5289a829ee0ad0c","transactionIndex":"0x0","from":"cfxtest:aapywaaaaaaaaaaaaaaaaaaaaaaaaaauaeutrs455h","to":"cfxtest:aapywaaaaaaaaaaaaaaaaaaaaaaaaaauaeutrs455h","value":"0xde0b6b3a7640000","gasPrice":"0x4f790d55","gas":"0x5208","contractCreated":null,"data":"0x","storageLimit":"0x0","epochHeight":"0x27bc2","chainId":"0x22b8","status":"0x0","maxPriorityFeePerGas":"0x0","maxFeePerGas":"0x4f790d55","v":"0x1","r":"0x9d08a7f2189e8be844eb0fc0e695c84eac29f40653a9dab11360497793390e22","s":"0x1f712887d60b595eb73b71973dc3e17fd5978d5401532f6e15746d57ac834fb0","yParity":"0x1"}`,
		`{"type":"0x2","hash":"0x1b6a88dc91c1870f05242ee2121c36a9a16a736b510634f1c664bcd2cc02909b","nonce":"0x1","blockHash":"0x08659936ca25de4ac0e50555918941f45dbb9de8d867aa2ae5289a829ee0ad0c","transactionIndex":"0x0","from":"cfxtest:aapywaaaaaaaaaaaaaaaaaaaaaaaaaauaeutrs455h","to":"cfxtest:aapywaaaaaaaaaaaaaaaaaaaaaaaaaauaeutrs455h","value":"0xde0b6b3a7640000","gasPrice":"0x4f790d55","gas":"0x5208","contractCreated":null,"data":"0x","storageLimit":"0x0","epochHeight":"0x27bc2","chainId":"0x22b8","status":"0x0","maxPriorityFeePerGas":"0x0","maxFeePerGas":"0x4f790d55","v":"0x1","r":"0x9d08a7f2189e8be844eb0fc0e695c84eac29f40653a9dab11360497793390e22","s":"0x1f712887d60b595eb73b71973dc3e17fd5978d5401532f6e15746d57ac834fb0","yParity":"0x1"}`,
	}

	for _, expect := range table {
		var tx *Transaction
		err := json.Unmarshal([]byte(expect), &tx)
		assert.NoError(t, err)

		actual, err := json.Marshal(tx)
		assert.NoError(t, err)

		assert.Equal(t, expect, string(actual))
	}
}

func TestJsonMarshalTransactionStatus(t *testing.T) {
	testJsonMarshalTransactionStatus(t, TransactionStatus{
		packedOrReady: "packed",
	}, "packed", []byte("\"packed\""))

	testJsonMarshalTransactionStatus(t, TransactionStatus{
		pending: pending{"futureNonce"},
	}, "futureNonce", []byte("{\"pending\":\"futureNonce\"}"))

}
func testJsonMarshalTransactionStatus(t *testing.T, originTxStatus TransactionStatus, expectString string, expectJson []byte) {
	if originTxStatus.String() != expectString {
		t.Fatalf("expect string %#v, actual %#v", expectString, originTxStatus.String())
	}

	actualJson, _ := json.Marshal(originTxStatus)
	if !reflect.DeepEqual(actualJson, expectJson) {
		t.Fatalf("expect json %#v, actual %#v", string(expectJson), string(actualJson))
	}
}

func TestJsonUnmarshalTransactionStatus(t *testing.T) {
	testJsonUnmarshalTransactionStatus(t, []byte("\"packed\""), TransactionStatus{
		packedOrReady: "packed",
	})
	testJsonUnmarshalTransactionStatus(t, []byte("{\"pending\": \"futureNonce\"}"), TransactionStatus{
		pending: pending{"futureNonce"},
	})
}

func testJsonUnmarshalTransactionStatus(t *testing.T, originTxStatusJson []byte, expectTxStatus TransactionStatus) {
	actualTxStatus := TransactionStatus{}
	json.Unmarshal(originTxStatusJson, &actualTxStatus)
	if !reflect.DeepEqual(actualTxStatus, expectTxStatus) {
		t.Fatalf("expect %#v, actual %#v", expectTxStatus, actualTxStatus)
	}
}

func fatalIfErr(t *testing.T, err error) {
	if err != nil {
		t.Fatal(err)
	}
}
