// TestNewMsgGetBlockTxnsFromBlock tests whether the MsgGetBlockTxns is
// properly contructed by the TestNewMsgGetBlockTxnsFromBlock method.
TestNewMsgGetBlockTxnsFromBlock tests whether the MsgGetBlockTxns is
properly contructed by the TestNewMsgGetBlockTxnsFromBlock method.
// TestNewMsgGetBlockTxnsFromBlock tests whether the MsgGetBlockTxns is // properly contructed by the TestNewMsgGetBlockTxnsFromBlock method .
func TestNewMsgGetBlockTxnsFromBlock(t *testing.T) {
	txs := make([]*MsgTx, 5)
	for i := 0; i < 5; i++ {
		tx := *multiTx
		tx.Version = int32(i)
		txs[i] = &tx
	}
	block1 := NewMsgBlock(&BlockHeader{})
	txsCpy := make([]*MsgTx, 5)
	copy(txsCpy, txs)
	block1.Transactions = txsCpy
	block1.Transactions[0] = nil
	block1.Transactions[2] = nil
	block1.Transactions[3] = nil
	block2 := NewMsgBlock(&BlockHeader{})
	txsCpy2 := make([]*MsgTx, 5)
	copy(txsCpy2, txs)
	block2.Transactions = txsCpy2
	block2.Transactions[2] = nil
	block2.Transactions[4] = nil
	tests := []struct {
		block           *MsgBlock
		expectedIndexes []uint32
	}{
		{
			block1,
			[]uint32{0, 1, 0},
		},
		{
			block2,
			[]uint32{2, 1},
		},
	}
	for _, test := range tests {
		gbtxns := NewMsgGetBlockTxnsFromBlock(test.block)
		if len(gbtxns.Indexes) != len(test.expectedIndexes) {
			t.Errorf("Invalid number of indexes. Expected %d got %d", len(test.expectedIndexes), len(gbtxns.Indexes))
		}
		for i, expected := range test.expectedIndexes {
			if gbtxns.Indexes[i] != expected {
				t.Errorf("Invalid index %d. Expected %d got %d", i, expected, gbtxns.Indexes[0])
			}
		}
	}
}
func TestNewMsgGetBlockTxnsFromBlock ( t * testing . T ) { txs := make ( [ ] * MsgTx , 5 ) for i := 0 ; i < 5 ; i ++ { tx := * multiTx tx . Version = int32 ( i ) txs [ i ] = & tx } block1 := NewMsgBlock ( & BlockHeader { } ) txsCpy := make ( [ ] * MsgTx , 5 ) copy ( txsCpy , txs ) block1 . Transactions = txsCpy block1 . Transactions [ 0 ] = nil block1 . Transactions [ 2 ] = nil block1 . Transactions [ 3 ] = nil block2 := NewMsgBlock ( & BlockHeader { } ) txsCpy2 := make ( [ ] * MsgTx , 5 ) copy ( txsCpy2 , txs ) block2 . Transactions = txsCpy2 block2 . Transactions [ 2 ] = nil block2 . Transactions [ 4 ] = nil tests := [ ] struct { block * MsgBlock expectedIndexes [ ] uint32 } { { block1 , [ ] uint32 { 0 , 1 , 0 } , } , { block2 , [ ] uint32 { 2 , 1 } , } , } for _ , test := range tests { gbtxns := NewMsgGetBlockTxnsFromBlock ( test . block ) if len ( gbtxns . Indexes ) != len ( test . expectedIndexes ) { t . Errorf ( " " , len ( test . expectedIndexes ) , len ( gbtxns . Indexes ) ) } for i , expected := range test . expectedIndexes { if gbtxns . Indexes [ i ] != expected { t . Errorf ( " " , i , expected , gbtxns . Indexes [ 0 ] ) } } } }
TestNewMsgGetBlockTxnsFromBlock tests whether the MsgGetBlockTxns is
properly contructed by the TestNewMsgGetBlockTxnsFromBlock method.
TestNewMsgGetBlockTxnsFromBlock tests whether the MsgGetBlockTxns is properly contructed by the TestNewMsgGetBlockTxnsFromBlock method .
// First index zero // First index non-zero