Skip to content

Commit 41fe76b

Browse files
committed
Add more tests and some fixes
1 parent 723c4ed commit 41fe76b

30 files changed

Lines changed: 7193 additions & 69 deletions

blockchain/cashtokens_test.go

Lines changed: 559 additions & 0 deletions
Large diffs are not rendered by default.

blockchain/error.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ const (
223223
// ErrInvalidTxOrder indicates the order of the transactions in the block
224224
// does not follow the active transaction ordering consensus rule.
225225
ErrInvalidTxOrder
226+
227+
// ErrCashTokensValidation indicates the token data is invalid in some way
228+
ErrCashTokensValidation
226229
)
227230

228231
// Map of ErrorCode values back to their constant names for pretty printing.
@@ -270,6 +273,7 @@ var errorCodeStrings = map[ErrorCode]string{
270273
ErrInvalidTxOrder: "ErrInvalidTxOrder",
271274
ErrTooManySigChecks: "ErrTooManySigChecks",
272275
ErrTxTooManySigChecks: "ErrTxTooManySigChecks",
276+
ErrCashTokensValidation: "ErrCashTokensValidation",
273277
}
274278

275279
// String returns the ErrorCode as a human-readable name.

blockchain/fullblocktests/generate.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ func createSpendTx(spend *spendableOut, fee bchutil.Amount) *wire.MsgTx {
466466
SignatureScript: nil,
467467
})
468468
spendTx.AddTxOut(wire.NewTxOut(int64(spend.amount-fee),
469-
opTrueScript))
470-
spendTx.AddTxOut(wire.NewTxOut(0, uniqueOpReturnScript()))
469+
opTrueScript, wire.TokenData{}))
470+
spendTx.AddTxOut(wire.NewTxOut(0, uniqueOpReturnScript(), wire.TokenData{}))
471471

472472
return spendTx
473473
}
@@ -1249,7 +1249,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
12491249
for i := 0; i < txnsNeeded; i++ {
12501250
prevTx = createSpendTxForTx(prevTx, lowFee)
12511251
prevTx.TxOut[0].Value -= 2
1252-
prevTx.AddTxOut(wire.NewTxOut(2, p2shScript))
1252+
prevTx.AddTxOut(wire.NewTxOut(2, p2shScript, wire.TokenData{}))
12531253
b.AddTransaction(prevTx)
12541254
}
12551255
})
@@ -1823,7 +1823,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
18231823
const zeroCoin = int64(0)
18241824
spendTx := b.Transactions[1]
18251825
for i := 0; i < numAdditionalOutputs; i++ {
1826-
spendTx.AddTxOut(wire.NewTxOut(zeroCoin, opTrueScript))
1826+
spendTx.AddTxOut(wire.NewTxOut(zeroCoin, opTrueScript, wire.TokenData{}))
18271827
}
18281828

18291829
// Add transactions spending from the outputs added above that
@@ -1889,7 +1889,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
18891889
spendTx := b.Transactions[1]
18901890
for i := 0; i < numAdditionalOutputs; i++ {
18911891
opRetScript := uniqueOpReturnScript()
1892-
spendTx.AddTxOut(wire.NewTxOut(zeroCoin, opRetScript))
1892+
spendTx.AddTxOut(wire.NewTxOut(zeroCoin, opRetScript, wire.TokenData{}))
18931893
}
18941894
})
18951895
for i := uint32(2); i < 6; i++ {
@@ -2659,7 +2659,7 @@ func GeneratePhononBlocks() (tests [][]TestInstance, err error) {
26592659
unsortedTxs = append(unsortedTxs, bchutil.NewTx(tx0))
26602660

26612661
tx1 := wire.NewMsgTx(1)
2662-
tx1.AddTxOut(wire.NewTxOut(1000, script))
2662+
tx1.AddTxOut(wire.NewTxOut(1000, script, wire.TokenData{}))
26632663

26642664
for i := 0; i < blockchain.MaxTransactionSigChecks; i++ {
26652665
tx1.AddTxIn(&wire.TxIn{
@@ -2734,7 +2734,7 @@ func GeneratePhononBlocks() (tests [][]TestInstance, err error) {
27342734
unsortedTxs = append(unsortedTxs, bchutil.NewTx(tx0))
27352735

27362736
tx1 := wire.NewMsgTx(1)
2737-
tx1.AddTxOut(wire.NewTxOut(1000, script))
2737+
tx1.AddTxOut(wire.NewTxOut(1000, script, wire.TokenData{}))
27382738

27392739
for i := 0; i < blockchain.MaxTransactionSigChecks+1; i++ {
27402740
tx1.AddTxIn(&wire.TxIn{
@@ -2811,7 +2811,7 @@ func GeneratePhononBlocks() (tests [][]TestInstance, err error) {
28112811

28122812
for i := 0; i < ((32000000/blockchain.BlockMaxBytesMaxSigChecksRatio)/2)+1; i++ {
28132813
tx1 := wire.NewMsgTx(1)
2814-
tx1.AddTxOut(wire.NewTxOut(1000, script))
2814+
tx1.AddTxOut(wire.NewTxOut(1000, script, wire.TokenData{}))
28152815

28162816
tx1.AddTxIn(&wire.TxIn{
28172817
PreviousOutPoint: so.prevOut,

blockchain/scriptval.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ out:
7272
v.sendResult(err)
7373
break out
7474
}
75-
7675
// Create a new script engine for the script pair.
7776
sigScript := txIn.SignatureScript
7877
pkScript := utxo.PkScript()
@@ -99,6 +98,11 @@ out:
9998
utxoEntryCache.AddEntry(i, *wire.NewTxOut(u.amount, u.pkScript, u.tokenData))
10099
}
101100

101+
_, err := wire.RunCashTokensValidityAlgorithm(utxoEntryCache, txVI.tx.MsgTx())
102+
if err != nil {
103+
v.sendResult(err)
104+
}
105+
102106
vm, err := txscript.NewEngine(pkScript, txVI.tx.MsgTx(),
103107
txVI.txInIndex, v.flags, v.sigCache, txVI.sigHashes,
104108
utxoEntryCache, inputAmount)

blockchain/testdata/bch_vmb_tests_before_chip_cashtokens_invalid.json

Lines changed: 1374 additions & 0 deletions
Large diffs are not rendered by default.

blockchain/testdata/bch_vmb_tests_before_chip_cashtokens_invalid_reasons.json

Lines changed: 1374 additions & 0 deletions
Large diffs are not rendered by default.

blockchain/testdata/bch_vmb_tests_before_chip_cashtokens_nonstandard.json

Lines changed: 336 additions & 0 deletions
Large diffs are not rendered by default.

blockchain/testdata/bch_vmb_tests_before_chip_cashtokens_nonstandard_reasons.json

Lines changed: 336 additions & 0 deletions
Large diffs are not rendered by default.

blockchain/testdata/bch_vmb_tests_before_chip_cashtokens_standard.json

Lines changed: 38 additions & 0 deletions
Large diffs are not rendered by default.

blockchain/testdata/bch_vmb_tests_chip_cashtokens_invalid.json

Lines changed: 576 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)