Skip to content

Commit

Permalink
Add test for ambiguous transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewLM committed Aug 17, 2023
1 parent 253c84f commit 67db51c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
17 changes: 17 additions & 0 deletions coinlib/test/tx/transaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ void main() {

});

test("ambiguous tx", () {

expectFullVector(
Transaction.fromHex(ambiguousHex, expectWitness: false),
ambiguousLegacy,
);

expectFullVector(
Transaction.fromHex(ambiguousHex, expectWitness: true),
ambiguousWitness,
);

// Witness assumed by default
expectFullVector(Transaction.fromHex(ambiguousHex), ambiguousWitness);

});

test("signatureHash", () {

final tx = Transaction.fromHex(sigHashTxHex);
Expand Down
56 changes: 56 additions & 0 deletions coinlib/test/vectors/tx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,62 @@ final validTxVecs = [

];

// Should deserialize as both legacy and witness transactions
final ambiguousHex = "03000000000101000000000000002d00000000000000000000000000000000000000000000000000000000005151510b01010203040506070800010000000000";

final ambiguousLegacy = TxVector(
obj: Transaction(
version: 3,
inputs: [],
outputs: [
Output.fromScriptBytes(
BigInt.one,
hexToBytes(
"00000000000000000000000000000000000000000000000000000000005151510b010102030405060708000100",
),
),
],
),
hashHex: "c484fd792a2b6abc72572da2fdfbe207edbab594b5b3d7fa0e7963b78c29c60a",
isWitness: false,
isCoinBase: false,
isCoinStake: false,
complete: false,
size: 64,
inputTypes: [],
hex: ambiguousHex,
);

final ambiguousWitness = TxVector(
obj: Transaction(
version: 3,
inputs: [
WitnessInput(
prevOut: OutPoint.fromHex(
"0000000000000000000000000000000000000000000000002d00000000000000", 0,
),
witness: [Uint8List(0)],
sequence: 189878609,
),
],
outputs: [
Output.fromScriptBytes(
BigInt.parse("578437695752307201"),
Uint8List(0),
),
],
),
hashHex: "c484fd792a2b6abc72572da2fdfbe207edbab594b5b3d7fa0e7963b78c29c60a",
txidHex: "a7905e577851b18db40986854f4d549a4cb8e759379bf783a0585a117792df1d",
isWitness: true,
isCoinBase: false,
isCoinStake: false,
complete: true,
size: 64,
inputTypes: [WitnessInput],
hex: ambiguousHex,
);

class SigHashVector {
final int inputN;
final String scriptCodeAsm;
Expand Down

0 comments on commit 67db51c

Please sign in to comment.