// TestMsgGetBlockTxns_RequestedTransactions tests whether the transactions returned
// by the RequestedTransactions method are correct.
TestMsgGetBlockTxns_RequestedTransactions tests whether the transactions returned
by the RequestedTransactions method are correct.
// TestMsgGetBlockTxns_RequestedTransactions tests whether the transactions returned // by the RequestedTransactions method are correct .
func TestMsgGetBlockTxns_RequestedTransactions(t *testing.T) {
	tests := []struct {
		requestedIndexes []uint32
		expectedTxInexes []uint32
	}{
		{
			[]uint32{0, 1, 1},
			[]uint32{0, 2, 4},
		},
		{
			[]uint32{2, 0, 0},
			[]uint32{2, 3, 4},
		},
	}
	for _, test := range tests {
		txs := make([]*MsgTx, 5)
		for i := 0; i < 5; i++ {
			tx := *multiTx
			tx.Version = int32(i)
			txs[i] = &tx
		}
		block := NewMsgBlock(&BlockHeader{})
		block.Transactions = txs
		gbtxns := NewMsgGetBlockTxns(block.BlockHash(), test.requestedIndexes)
		rt, err := gbtxns.RequestedTransactions(block)
		if err != nil {
			t.Fatalf("Failed to create requested transactions: %s", err)
		}
		if len(rt) != len(test.expectedTxInexes) {
			t.Errorf("Invalid number of txs. Expected %d got %d", len(test.expectedTxInexes), len(rt))
		}
		for i, index := range test.expectedTxInexes {
			want := block.Transactions[index].TxHash()
			expected := rt[i].TxHash()
			if !expected.IsEqual(&want) {
				t.Errorf("Returned incorrect transaction for index %d. Expected %v got %v", i, expected, want)
			}
		}
	}
}
func TestMsgGetBlockTxns_RequestedTransactions ( t * testing . T ) { tests := [ ] struct { requestedIndexes [ ] uint32 expectedTxInexes [ ] uint32 } { { [ ] uint32 { 0 , 1 , 1 } , [ ] uint32 { 0 , 2 , 4 } , } , { [ ] uint32 { 2 , 0 , 0 } , [ ] uint32 { 2 , 3 , 4 } , } , } for _ , test := range tests { txs := make ( [ ] * MsgTx , 5 ) for i := 0 ; i < 5 ; i ++ { tx := * multiTx tx . Version = int32 ( i ) txs [ i ] = & tx } block := NewMsgBlock ( & BlockHeader { } ) block . Transactions = txs gbtxns := NewMsgGetBlockTxns ( block . BlockHash ( ) , test . requestedIndexes ) rt , err := gbtxns . RequestedTransactions ( block ) if err != nil { t . Fatalf ( " " , err ) } if len ( rt ) != len ( test . expectedTxInexes ) { t . Errorf ( " " , len ( test . expectedTxInexes ) , len ( rt ) ) } for i , index := range test . expectedTxInexes { want := block . Transactions [ index ] . TxHash ( ) expected := rt [ i ] . TxHash ( ) if ! expected . IsEqual ( & want ) { t . Errorf ( " " , i , expected , want ) } } } }
TestMsgGetBlockTxns_RequestedTransactions tests whether the transactions returned
by the RequestedTransactions method are correct.
TestMsgGetBlockTxns_RequestedTransactions tests whether the transactions returned by the RequestedTransactions method are correct .
// First index zero // First index non-zero