mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
dcrutil: Add tests for NewTxDeep.
This adds tests for NewTxDeep to make sure new MsgTx is deeply copied.
This commit is contained in:
parent
9ae4670a7e
commit
edba35c971
@ -121,3 +121,53 @@ func TestTxErrors(t *testing.T) {
|
||||
"got %v, want %v", err, io.EOF)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewTxDeep tests the API for Tx deep copy.
|
||||
func TestNewTxDeep(t *testing.T) {
|
||||
orgTx := Block100000.Transactions[0]
|
||||
copyTxDeep := NewTxDeep(orgTx)
|
||||
copyTx := copyTxDeep.MsgTx()
|
||||
|
||||
// Ensure original and copied has equal values to original transaction.
|
||||
if !reflect.DeepEqual(orgTx, copyTx) {
|
||||
t.Fatalf("MsgTx is not equal - got %v, want %v",
|
||||
spew.Sdump(copyTx), spew.Sdump(&orgTx))
|
||||
}
|
||||
|
||||
// Ensure original and copied transaction referring to different allocations.
|
||||
if orgTx == copyTx {
|
||||
t.Fatal("MsgTx is referring to the same allocation")
|
||||
}
|
||||
|
||||
// Compare each original and copied input transaction allocations.
|
||||
for i := 0; i < len(orgTx.TxIn); i++ {
|
||||
// Ensure input transactions referring to different allocations.
|
||||
if orgTx.TxIn[i] == copyTx.TxIn[i] {
|
||||
t.Errorf("TxIn #%d is referring to the same allocation", i)
|
||||
}
|
||||
|
||||
// Ensure previous transaction output points referring to different
|
||||
// allocations.
|
||||
if &orgTx.TxIn[i].PreviousOutPoint == ©Tx.TxIn[i].PreviousOutPoint {
|
||||
t.Errorf("PreviousOutPoint #%d is referring to the same allocation", i)
|
||||
}
|
||||
|
||||
// Ensure signature scripts referring to different allocations.
|
||||
if &orgTx.TxIn[i].SignatureScript[0] == ©Tx.TxIn[i].SignatureScript[0] {
|
||||
t.Errorf("SignatureScript #%d is referring to the same allocation", i)
|
||||
}
|
||||
}
|
||||
|
||||
// Compare each original and copied output transaction allocations.
|
||||
for i := 0; i < len(orgTx.TxOut); i++ {
|
||||
// Ensure output transactions referring to different allocations.
|
||||
if orgTx.TxOut[i] == copyTx.TxOut[i] {
|
||||
t.Errorf("TxOut #%d is referring to the same allocation", i)
|
||||
}
|
||||
|
||||
// Ensure PkScripts referring to different allocations.
|
||||
if &orgTx.TxOut[i].PkScript[0] == ©Tx.TxOut[i].PkScript[0] {
|
||||
t.Errorf("PkScript #%d is referring to the same allocation", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user