Skip to content

Commit

Permalink
[test] refs #279 - Add Test_getSkycoinTransactionInputsFromTxnHash
Browse files Browse the repository at this point in the history
  • Loading branch information
e1Ru1o committed Jan 26, 2020
1 parent b8a6817 commit eaad386
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/coin/skycoin/models/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,3 +1307,50 @@ func TestTransactionVerifySigned(t *testing.T) {
})
}
}

func Test_getSkycoinTransactionInputsFromTxnHash(t *testing.T) {
CleanGlobalMock()

inputs := []readable.TransactionInput{
readable.TransactionInput{
Hash: "hash1",
},
readable.TransactionInput{
Hash: "hash2",
},
readable.TransactionInput{
Hash: "hash3",
},
readable.TransactionInput{
Hash: "hash4",
},
}

for len(inputs) > 0 {
global_mock.On("TransactionVerbose", "hash").Return(
&readable.TransactionWithStatusVerbose{
Transaction: readable.TransactionVerbose{
BlockTransactionVerbose: readable.BlockTransactionVerbose{
In: inputs,
},
},
}, nil,
).Once()
t.Run("InputsFromTxnHash", func(t *testing.T) {
txnInputs, err := getSkycoinTransactionInputsFromTxnHash("hash")
require.NoError(t, err)
rawInputs := make([]readable.TransactionInput, len(txnInputs))
for i, in := range txnInputs {
skyIn, valid := in.(*SkycoinTransactionInput)
require.True(t, valid)
require.Nil(t, skyIn.spentOutput)
rawInputs[i] = skyIn.skyIn
}
requirethat.ElementsMatch(t, inputs, rawInputs)
})
inputs = inputs[:len(inputs)-1]
}
global_mock.On("TransactionVerbose", "hash").Return(nil, goerrors.New("failure"))
_, err := getSkycoinTransactionInputsFromTxnHash("hash")
require.Error(t, err)
}

0 comments on commit eaad386

Please sign in to comment.