github.com/amazechain/amc@v0.1.3/internal/avm/rlp/iterator_test.go (about)

     1  // Copyright 2023 The AmazeChain Authors
     2  // This file is part of the AmazeChain library.
     3  //
     4  // The AmazeChain library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The AmazeChain library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package rlp
    18  
    19  import (
    20  	"github.com/amazechain/amc/common/hexutil"
    21  	"testing"
    22  )
    23  
    24  // TestIterator tests some basic things about the ListIterator. A more
    25  // comprehensive test can be found in core/rlp_test.go, where we can
    26  // use both types and rlp without dependency cycles
    27  func TestIterator(t *testing.T) {
    28  	bodyRlpHex := "0xf902cbf8d6f869800182c35094000000000000000000000000000000000000aaaa808a000000000000000000001ba01025c66fad28b4ce3370222624d952c35529e602af7cbe04f667371f61b0e3b3a00ab8813514d1217059748fd903288ace1b4001a4bc5fbde2790debdc8167de2ff869010182c35094000000000000000000000000000000000000aaaa808a000000000000000000001ca05ac4cf1d19be06f3742c21df6c49a7e929ceb3dbaf6a09f3cfb56ff6828bd9a7a06875970133a35e63ac06d360aa166d228cc013e9b96e0a2cae7f55b22e1ee2e8f901f0f901eda0c75448377c0e426b8017b23c5f77379ecf69abc1d5c224284ad3ba1c46c59adaa00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808080808080a00000000000000000000000000000000000000000000000000000000000000000880000000000000000"
    29  	bodyRlp := hexutil.MustDecode(bodyRlpHex)
    30  
    31  	it, err := NewListIterator(bodyRlp)
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  	// Check that txs exist
    36  	if !it.Next() {
    37  		t.Fatal("expected two elems, got zero")
    38  	}
    39  	txs := it.Value()
    40  	// Check that uncles exist
    41  	if !it.Next() {
    42  		t.Fatal("expected two elems, got one")
    43  	}
    44  	txit, err := NewListIterator(txs)
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	var i = 0
    49  	for txit.Next() {
    50  		if txit.err != nil {
    51  			t.Fatal(txit.err)
    52  		}
    53  		i++
    54  	}
    55  	if exp := 2; i != exp {
    56  		t.Errorf("count wrong, expected %d got %d", i, exp)
    57  	}
    58  }