Skip to content

Commit 77887b8

Browse files
committed
tests for InputCollectionMutator
1 parent 6f7d4f2 commit 77887b8

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/Transaction/Mutator/InputCollectionMutator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function set(int $i, TransactionInputInterface $input): InputCollectionMu
8888
if ($i > count($this->set)) {
8989
throw new \InvalidArgumentException();
9090
}
91-
$this->set[$i] = $input;
91+
$this->set[$i] = new InputMutator($input);
9292
return $this;
9393
}
9494
}

src/Transaction/Mutator/OutputCollectionMutator.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ public function null(): OutputCollectionMutator
7272
return $this;
7373
}
7474

75-
/**
76-
* @param TransactionOutputInterface $output
77-
* @return $this
78-
*/
7975
public function add(TransactionOutputInterface $output): OutputCollectionMutator
8076
{
8177
$size = $this->count();

tests/Transaction/Mutator/InputCollectionMutatorTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,25 @@ public function testNull()
6363

6464
$this->assertEquals(0, count($outputs));
6565
}
66+
67+
public function testSet()
68+
{
69+
$collection = [
70+
new TransactionInput(new OutPoint(Buffer::hex('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), 5), new Script()),
71+
new TransactionInput(new OutPoint(Buffer::hex('baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), 10), new Script()),
72+
];
73+
74+
$mutator = new InputCollectionMutator($collection);
75+
$new = new TransactionInput(new OutPoint(Buffer::hex('baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), 11), new Script());
76+
$mutator->set(1, $new);
77+
$newCollection = $mutator->done();
78+
$this->assertTrue($newCollection[1]->equals($new));
79+
}
80+
81+
public function testInvalidIndex()
82+
{
83+
$mutator = new InputCollectionMutator([]);
84+
$this->expectException(\OutOfRangeException::class);
85+
$mutator->offsetGet(10);
86+
}
6687
}

0 commit comments

Comments
 (0)