Skip to content

Commit

Permalink
Fix witness immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewLM committed Oct 28, 2023
1 parent 2085b1b commit 0ad9621
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions coinlib/lib/src/tx/inputs/witness_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class WitnessInput extends RawInput {

WitnessInput({
required OutPoint prevOut,
required this.witness,
required List<Uint8List> witness,
int sequence = Input.sequenceFinal,
}) : super(
}) : witness = List.unmodifiable(witness), super(
prevOut: prevOut,
scriptSig: Uint8List(0),
sequence: sequence,
Expand Down
17 changes: 17 additions & 0 deletions coinlib/test/tx/inputs/witness_input_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:typed_data';
import 'package:coinlib/coinlib.dart';
import 'package:test/test.dart';
import '../../vectors/inputs.dart';
import '../../vectors/tx.dart';

void main() {

Expand Down Expand Up @@ -39,6 +40,22 @@ void main() {
expect(WitnessInput.match(rawWithScriptSig, witness), null);
});

test("witness elements are immutable", () {

final mutatedWitness = [hexToBytes("0000")];

final input = WitnessInput(
prevOut: examplePrevOut,
witness: mutatedWitness,
);

mutatedWitness[0] = hexToBytes("ffff");
expect(input.witness, [hexToBytes("0000")]);

expect(() => input.witness[0] = Uint8List(1), throwsA(anything));

});

});

}

0 comments on commit 0ad9621

Please sign in to comment.