Skip to content

Commit

Permalink
tests for InputCollectionMutator
Browse files Browse the repository at this point in the history
  • Loading branch information
afk11 committed Apr 24, 2021
1 parent 3dea5b8 commit 9c327ef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Transaction/Mutator/InputCollectionMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function set(int $i, TransactionInputInterface $input): InputCollectionMu
if ($i > count($this->set)) {
throw new \InvalidArgumentException();
}
$this->set[$i] = $input;
$this->set[$i] = new InputMutator($input);
return $this;
}
}
4 changes: 0 additions & 4 deletions src/Transaction/Mutator/OutputCollectionMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ public function null(): OutputCollectionMutator
return $this;
}

/**
* @param TransactionOutputInterface $output
* @return $this
*/
public function add(TransactionOutputInterface $output): OutputCollectionMutator
{
$size = $this->count();
Expand Down
21 changes: 21 additions & 0 deletions tests/Transaction/Mutator/InputCollectionMutatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,25 @@ public function testNull()

$this->assertEquals(0, count($outputs));
}

public function testSet()
{
$collection = [
new TransactionInput(new OutPoint(Buffer::hex('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), 5), new Script()),
new TransactionInput(new OutPoint(Buffer::hex('baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), 10), new Script()),
];

$mutator = new InputCollectionMutator($collection);
$new = new TransactionInput(new OutPoint(Buffer::hex('baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), 11), new Script());
$mutator->set(1, $new);
$newCollection = $mutator->done();
$this->assertTrue($newCollection[1]->equals($new));
}

public function testInvalidIndex()
{
$mutator = new InputCollectionMutator([]);
$this->expectException(\OutOfRangeException::class);
$mutator->offsetGet(10);
}
}

0 comments on commit 9c327ef

Please sign in to comment.