@@ -86,28 +86,59 @@ func TestNewPoLTx_NilPubkey(t *testing.T) {
8686 }
8787}
8888
89- // TestNewPoLTx_NegativeBlockNumber ensures negative block numbers are handled
90- // without panicking (uint64 wrap-around is expected).
91- func TestNewPoLTx_NegativeBlockNumber (t * testing.T ) {
89+ // TestNewPoLTx_InvalidBlockNumber ensures that block numbers <= 0 are rejected.
90+ func TestNewPoLTx_InvalidBlockNumber (t * testing.T ) {
9291 chainID := big .NewInt (1 )
9392 distributor := common.Address {}
94- negBlock := big .NewInt (- 1 )
9593 baseFee := big .NewInt (1000000000 )
96-
97- tx , err := NewPoLTx (chainID , distributor , negBlock , params .PoLTxGasLimit , baseFee , samplePubkey ())
98- if err != nil {
99- t .Fatalf ("unexpected error: %v" , err )
100- }
101- if got , want := tx .Nonce (), negBlock .Uint64 (); got != want {
102- t .Fatalf ("nonce mismatch: have %d, want %d" , got , want )
103- }
94+ expectedErr := "PoL tx must only be created for a block number greater than 0"
95+
96+ testCases := []struct {
97+ name string
98+ blockNumber * big.Int
99+ }{
100+ {"negative block number" , big .NewInt (- 1 )},
101+ {"zero block number" , big .NewInt (0 )},
102+ }
103+
104+ for _ , tc := range testCases {
105+ t .Run (tc .name , func (t * testing.T ) {
106+ tx , err := NewPoLTx (chainID , distributor , tc .blockNumber , params .PoLTxGasLimit , baseFee , samplePubkey ())
107+ if err == nil {
108+ t .Fatalf ("expected error for block number %v, but got nil" , tc .blockNumber )
109+ }
110+ if tx != nil {
111+ t .Fatalf ("expected nil transaction when error occurs, but got %v" , tx )
112+ }
113+ if err .Error () != expectedErr {
114+ t .Fatalf ("error message mismatch: have %q, want %q" , err .Error (), expectedErr )
115+ }
116+ })
117+ }
118+
119+ // Test that positive block numbers work correctly
120+ t .Run ("positive block number" , func (t * testing.T ) {
121+ positiveBlock := big .NewInt (123 )
122+ tx , err := NewPoLTx (chainID , distributor , positiveBlock , params .PoLTxGasLimit , baseFee , samplePubkey ())
123+ if err != nil {
124+ t .Fatalf ("unexpected error for positive block number: %v" , err )
125+ }
126+ if tx == nil {
127+ t .Fatalf ("expected transaction for positive block number, but got nil" )
128+ }
129+ // Nonce should be blockNumber - 1 (as per the implementation)
130+ expectedNonce := positiveBlock .Uint64 () - 1
131+ if got := tx .Nonce (); got != expectedNonce {
132+ t .Fatalf ("nonce mismatch: have %d, want %d" , got , expectedNonce )
133+ }
134+ })
104135}
105136
106137// TestIsPoLDistribution exercises positive and negative cases for the helper.
107138func TestIsPoLDistribution (t * testing.T ) {
108139 distributor := common .HexToAddress ("0x1000000000000000000000000000000000000001" )
109140 baseFee := big .NewInt (1000000000 )
110- tx , err := NewPoLTx (big .NewInt (1 ), distributor , big .NewInt (0 ), params .PoLTxGasLimit , baseFee , samplePubkey ())
141+ tx , err := NewPoLTx (big .NewInt (1 ), distributor , big .NewInt (1 ), params .PoLTxGasLimit , baseFee , samplePubkey ())
111142 if err != nil {
112143 t .Fatalf ("failed to build PoL tx: %v" , err )
113144 }
@@ -143,7 +174,7 @@ func TestIsPoLDistribution(t *testing.T) {
143174// TestPoLTx_RawSignatureValues confirms that PoLTx reports no signature.
144175func TestPoLTx_RawSignatureValues (t * testing.T ) {
145176 baseFee := big .NewInt (1000000000 )
146- tx , err := NewPoLTx (big .NewInt (1 ), common.Address {}, big .NewInt (0 ), params .PoLTxGasLimit , baseFee , samplePubkey ())
177+ tx , err := NewPoLTx (big .NewInt (1 ), common.Address {}, big .NewInt (1 ), params .PoLTxGasLimit , baseFee , samplePubkey ())
147178 if err != nil {
148179 t .Fatalf ("failed to create PoL tx: %v" , err )
149180 }
0 commit comments