@@ -6,101 +6,86 @@ import (
6
6
"testing"
7
7
8
8
"github.com/ethereum/go-ethereum/common"
9
- "github.com/ethereum/go-ethereum/core"
10
9
"github.com/ethereum/go-ethereum/core/types"
11
10
"github.com/ethereum/go-ethereum/crypto"
12
11
"github.com/ethereum/go-ethereum/log"
13
12
"github.com/ethereum/go-ethereum/params"
14
13
"github.com/ethereum/go-ethereum/rlp"
15
- "github.com/stretchr/testify/require "
14
+ "github.com/stretchr/testify/suite "
16
15
16
+ "github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/testutils"
17
17
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/utils"
18
+ "github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc"
18
19
)
19
20
20
21
var (
21
- maxBlocksGasLimit = uint64 (50 )
22
- maxTxlistBytes = uint64 (10000 )
23
- chainID = genesis .Config .ChainID
24
- testKey , _ = crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
25
- testAddr = crypto .PubkeyToAddress (testKey .PublicKey )
26
- genesis = & core.Genesis {
27
- Config : params .AllEthashProtocolChanges ,
28
- Alloc : types.GenesisAlloc {testAddr : {Balance : big .NewInt (2e15 )}},
29
- ExtraData : []byte ("test genesis" ),
30
- Timestamp : 9000 ,
31
- BaseFee : big .NewInt (params .InitialBaseFee ),
32
- }
22
+ chainID = new (big.Int ).SetUint64 (167001 )
23
+ testKey , _ = crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
24
+ testAddr = crypto .PubkeyToAddress (testKey .PublicKey )
33
25
)
34
26
35
- func TestDecomporess (t * testing.T ) {
36
- d := NewTxListDecompressor (
37
- maxBlocksGasLimit ,
38
- maxTxlistBytes ,
27
+ type TxListDecompressorTestSuite struct {
28
+ testutils.ClientTestSuite
29
+ d * TxListDecompressor
30
+ }
31
+
32
+ func (s * TxListDecompressorTestSuite ) SetupTest () {
33
+ s .ClientTestSuite .SetupTest ()
34
+ s .d = NewTxListDecompressor (
35
+ params .MaxGasLimit ,
36
+ rpc .BlockMaxTxListBytes ,
39
37
chainID ,
40
38
)
39
+ }
40
+
41
+ func (s * TxListDecompressorTestSuite ) TestZeroBytes () {
42
+ s .Empty (s .d .TryDecompress (chainID , []byte {}, false ))
43
+ }
44
+
45
+ func (s * TxListDecompressorTestSuite ) TestCalldataSize () {
46
+ s .Empty (s .d .TryDecompress (chainID , randBytes (rpc .BlockMaxTxListBytes + 1 ), false ))
47
+ s .Empty (s .d .TryDecompress (chainID , randBytes (rpc .BlockMaxTxListBytes - 1 ), false ))
48
+ }
49
+
50
+ func (s * TxListDecompressorTestSuite ) TestValidTxList () {
41
51
compressed , err := utils .Compress (rlpEncodedTransactionBytes (1 , true ))
42
- require .NoError (t , err )
43
-
44
- tests := []struct {
45
- name string
46
- blockID * big.Int
47
- txListBytes []byte
48
- decompressed []byte
49
- }{
50
- {
51
- "txListBytes binary too large" ,
52
- chainID ,
53
- randBytes (maxTxlistBytes + 1 ),
54
- []byte {},
55
- },
56
- {
57
- "txListBytes not decodable to rlp" ,
58
- chainID ,
59
- randBytes (0x1 ),
60
- []byte {},
61
- },
62
- {
63
- "success empty tx list" ,
64
- chainID ,
65
- rlpEncodedTransactionBytes (0 , true ),
66
- []byte {},
67
- },
68
- {
69
- "success non-empty tx list" ,
70
- chainID ,
71
- compressed ,
72
- rlpEncodedTransactionBytes (1 , true ),
73
- },
74
- }
52
+ s .Nil (err )
53
+ decompressed , err := utils .Decompress (compressed )
54
+ s .Nil (err )
75
55
76
- for _ , tt := range tests {
77
- t .Run (tt .name , func (t * testing.T ) {
78
- require .Equal (t , tt .decompressed , d .TryDecompress (tt .blockID , tt .txListBytes , false ))
79
- })
80
- }
56
+ s .Equal (s .d .TryDecompress (chainID , compressed , true ), decompressed )
57
+ s .Equal (s .d .TryDecompress (chainID , compressed , false ), decompressed )
58
+ }
59
+
60
+ func (s * TxListDecompressorTestSuite ) TestInvalidTxList () {
61
+ compressed , err := utils .Compress (randBytes (1024 ))
62
+ s .Nil (err )
63
+
64
+ s .Zero (len (s .d .TryDecompress (chainID , compressed , true )))
65
+ s .Zero (len (s .d .TryDecompress (chainID , compressed , false )))
66
+ }
67
+
68
+ func (s * TxListDecompressorTestSuite ) TestInvalidZlibBytes () {
69
+ s .Zero (len (s .d .TryDecompress (chainID , randBytes (1024 ), true )))
70
+ s .Zero (len (s .d .TryDecompress (chainID , randBytes (1024 ), false )))
71
+ }
72
+
73
+ func TestDriverTestSuite (t * testing.T ) {
74
+ suite .Run (t , new (TxListDecompressorTestSuite ))
81
75
}
82
76
83
77
func rlpEncodedTransactionBytes (l int , signed bool ) []byte {
84
78
txs := make (types.Transactions , 0 )
85
79
for i := 0 ; i < l ; i ++ {
86
80
var tx * types.Transaction
87
81
if signed {
88
- txData := & types.LegacyTx {
89
- Nonce : 1 ,
90
- To : & testAddr ,
91
- GasPrice : common .Big256 ,
92
- Value : common .Big1 ,
93
- Gas : 10 ,
94
- }
95
-
96
- tx = types .MustSignNewTx (testKey , types .LatestSigner (genesis .Config ), txData )
82
+ txData := & types.LegacyTx {Nonce : 1 , To : & testAddr , GasPrice : common .Big256 , Value : common .Big1 , Gas : 10 }
83
+
84
+ tx = types .MustSignNewTx (testKey , types .LatestSigner (& params.ChainConfig {ChainID : chainID }), txData )
97
85
} else {
98
86
tx = types .NewTransaction (1 , testAddr , common .Big1 , 10 , new (big.Int ).SetUint64 (10 * params .GWei ), nil )
99
87
}
100
- txs = append (
101
- txs ,
102
- tx ,
103
- )
88
+ txs = append (txs , tx )
104
89
}
105
90
b , _ := rlp .EncodeToBytes (txs )
106
91
return b
0 commit comments