Skip to content

Commit

Permalink
feat: add multi signature tests (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsobries authored Jul 30, 2024
1 parent 18d4644 commit 9ae1831
Show file tree
Hide file tree
Showing 17 changed files with 335 additions and 25 deletions.
6 changes: 6 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ abstract class TestCase extends BaseTestCase

protected $secondPassphrase = 'this is a top secret second passphrase';

protected $passphrases = [
'album pony urban cheap small blade cannon silent run reveal luxury glad predict excess fire beauty hollow reward solar egg exclude leaf sight degree',
'hen slogan retire boss upset blame rocket slender area arch broom bring elder few milk bounce execute page evoke once inmate pear marine deliver',
'top visa use bacon sun infant shrimp eye bridge fantasy chair sadness stable simple salad canoe raw hill target connect avoid promote spider category',
];

protected function setUp(): void
{
Network::set(Mainnet::new());
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/Transactions/Builder/MultiPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ public function it_should_sign_it_with_a_passphrase()
}

/** @test */
public function it_should_multi_sign()
{
$fixture = $this->getTransactionFixture('multi_payment', 'multi-payment-multi-sign');

$builder = MultiPaymentBuilder::new()
->withNonce($fixture['data']['nonce'])
->withNetwork($fixture['data']['network'])
->add($fixture['data']['asset']['payments'][0]['recipientId'], $fixture['data']['asset']['payments'][0]['amount'])
->add($fixture['data']['asset']['payments'][1]['recipientId'], $fixture['data']['asset']['payments'][1]['amount']);

foreach ($this->passphrases as $index => $passphrase) {
$builder->multiSign($passphrase, $index);
}

$builder->sign($this->passphrase);

$this->assertTrue($builder->verify());

$this->assertSameSerializationMultisignature($fixture['serialized'], Serializer::new($builder->transaction)->serialize()->getHex(), 3);

$this->assertSameTransactions($fixture, $builder->transaction->data);
}

public function it_should_sign_it_with_a_second_passphrase()
{
$transaction = MultiPaymentBuilder::new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ public function it_should_match_fixture_passphrase()
->multiSignatureAsset([
'min' => $fixture['data']['asset']['multiSignature']['min'],
'publicKeys' => $fixture['data']['asset']['multiSignature']['publicKeys'],
])
->multiSign('album pony urban cheap small blade cannon silent run reveal luxury glad predict excess fire beauty hollow reward solar egg exclude leaf sight degree', 0)
->multiSign('hen slogan retire boss upset blame rocket slender area arch broom bring elder few milk bounce execute page evoke once inmate pear marine deliver', 1)
->multiSign('top visa use bacon sun infant shrimp eye bridge fantasy chair sadness stable simple salad canoe raw hill target connect avoid promote spider category', 2)
->sign($this->passphrase);
]);

foreach ($this->passphrases as $index => $passphrase) {
$builder->multiSign($passphrase, $index);
}

$builder->sign($this->passphrase);

$serialized = Serializer::new($builder->transaction)->serialize()->getHex();
$this->assertTrue($builder->verify());
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Transactions/Builder/TransferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ public function it_should_sign_it_with_a_passphrase()
}

/** @test */
public function it_should_multi_sign()
{
$fixture = $this->getTransactionFixture('transfer', 'transfer-multi-sign');

$builder = TransferBuilder::new()
->recipient($fixture['data']['recipientId'])
->amount($fixture['data']['amount'])
->withFee($fixture['data']['fee'])
->withNonce($fixture['data']['nonce'])
->withNetwork($fixture['data']['network']);

foreach ($this->passphrases as $index => $passphrase) {
$builder->multiSign($passphrase, $index);
}

$builder->sign($this->passphrase);

$this->assertTrue($builder->verify());

$this->assertSameSerializationMultisignature($fixture['serialized'], Serializer::new($builder->transaction)->serialize()->getHex(), 3);

$this->assertSameTransactions($fixture, $builder->transaction->data);
}

public function it_should_sign_it_with_a_second_passphrase()
{
$transaction = TransferBuilder::new()
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/Transactions/Builder/UsernameRegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ public function it_should_sign_it_with_a_passphrase()
}

/** @test */
public function it_should_multi_sign()
{
$fixture = $this->getTransactionFixture('username_registration', 'username-registration-multi-sign');

$builder = UsernameRegistrationBuilder::new()
->withFee($fixture['data']['fee'])
->withNonce($fixture['data']['nonce'])
->withNetwork($fixture['data']['network'])
->usernameAsset($fixture['data']['asset']['username']);

foreach ($this->passphrases as $index => $passphrase) {
$builder->multiSign($passphrase, $index);
}

$builder->sign($this->passphrase);

$this->assertTrue($builder->verify());

$this->assertSameSerializationMultisignature($fixture['serialized'], Serializer::new($builder->transaction)->serialize()->getHex(), 3);

$this->assertSameTransactions($fixture, $builder->transaction->data);
}

public function it_should_sign_it_with_a_second_passphrase()
{
$transaction = UsernameRegistrationBuilder::new()
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Transactions/Builder/UsernameResignationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ public function it_should_sign_it_with_a_passphrase()
}

/** @test */
public function it_should_multi_sign()
{
$fixture = $this->getTransactionFixture('username_resignation', 'username-resignation-multi-sign');

$builder = UsernameResignationBuilder::new()
->withFee($fixture['data']['fee'])
->withNonce($fixture['data']['nonce'])
->withNetwork($fixture['data']['network']);

foreach ($this->passphrases as $index => $passphrase) {
$builder->multiSign($passphrase, $index);
}

$builder->sign($this->passphrase);

$this->assertTrue($builder->verify());

$this->assertSameSerializationMultisignature($fixture['serialized'], Serializer::new($builder->transaction)->serialize()->getHex(), 3);

$this->assertSameTransactions($fixture, $builder->transaction->data);
}

public function it_should_sign_it_with_a_second_passphrase()
{
$transaction = UsernameResignationBuilder::new()
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/Transactions/Builder/ValidatorRegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ public function it_should_sign_it_with_a_passphrase()
}

/** @test */
public function it_should_multi_sign()
{
$fixture = $this->getTransactionFixture('validator_registration', 'validator-registration-multi-sign');

$builder = ValidatorRegistrationBuilder::new()
->withFee($fixture['data']['fee'])
->withNonce($fixture['data']['nonce'])
->withNetwork($fixture['data']['network'])
->publicKeyAsset($fixture['data']['asset']['validatorPublicKey']);

foreach ($this->passphrases as $index => $passphrase) {
$builder->multiSign($passphrase, $index);
}

$builder->sign($this->passphrase);

$this->assertTrue($builder->verify());

$this->assertSameSerializationMultisignature($fixture['serialized'], Serializer::new($builder->transaction)->serialize()->getHex(), 3);

$this->assertSameTransactions($fixture, $builder->transaction->data);
}

public function it_should_sign_it_with_a_second_passphrase()
{
$transaction = ValidatorRegistrationBuilder::new()
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/Transactions/Builder/ValidatorResignationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ public function it_should_sign_it_with_a_passphrase()
}

/** @test */
public function it_should_multi_sign()
{
$fixture = $this->getTransactionFixture('validator_resignation', 'validator-resignation-multi-sign');
$builder = ValidatorResignationBuilder::new()
->withFee($fixture['data']['fee'])
->withNonce($fixture['data']['nonce'])
->withNetwork($fixture['data']['network']);

foreach ($this->passphrases as $index => $passphrase) {
$builder->multiSign($passphrase, $index);
}

$builder->sign($this->passphrase);

$this->assertTrue($builder->verify());

$this->assertSameSerializationMultisignature($fixture['serialized'], Serializer::new($builder->transaction)->serialize()->getHex(), 3);

$this->assertSameTransactions($fixture, $builder->transaction->data);
}

public function it_should_sign_it_with_a_second_passphrase()
{
$transaction = ValidatorResignationBuilder::new()
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/Transactions/Builder/VoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ public function it_should_sign_it_with_a_passphrase()
}

/** @test */
public function it_should_multi_sign()
{
$fixture = $this->getTransactionFixture('vote', 'vote-multi-sign');
$builder = VoteBuilder::new()
->votes($fixture['data']['asset']['votes'])
->withNonce($fixture['data']['nonce'])
->withNetwork($fixture['data']['network']);

foreach ($this->passphrases as $index => $passphrase) {
$builder->multiSign($passphrase, $index);
}

$builder->sign($this->passphrase);

$this->assertTrue($builder->verify());

$this->assertSameSerializationMultisignature($fixture['serialized'], Serializer::new($builder->transaction)->serialize()->getHex(), 3);

$this->assertSameTransactions($fixture, $builder->transaction->data);
}

public function it_should_sign_it_with_a_second_passphrase()
{
$transaction = VoteBuilder::new()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"data": {
"version": 1,
"network": 30,
"typeGroup": 1,
"type": 6,
"nonce": "0",
"senderPublicKey": "023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d3",
"fee": "10000000",
"amount": "3",
"asset": {
"payments": [
{
"amount": "1",
"recipientId": "0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A"
},
{
"amount": "2",
"recipientId": "0x27FA7CaFFaAE77dDb9AB232FDBDa56D5e5Af2393"
}
]
},
"signature": "cf4e94776e768110e62961747f39b68993d4ff5ec2171cad2fab6d77babb2ce31181f005876031d43e6d7732770c6aca73b33057c7aad6279cf2da03829a7b62",
"signatures": [
"006581c24bbe49e57127604b18d2efdd8d1d2bfe23f9b1e7f15b3f46a647b976e79884b61331546c5844ded781974e181a03a4066f858020fb347ad9628773b465",
"011fb86a8ddbddbed012ff46fc0f3c9a30f3c1544d7a32b9355c318ad453837615e8399f676856c97cf6dcb8d18507ff9c0ffe195d23624e296182477644ed3689",
"023aa80e3663d737716818978ffbae59a8a9f32257a341e1391ca1e0fd744f3382b41e507dca92fa91f98e2024b67938420aaf0c268266dfe4d1f92e81cb3a0421"
],
"id": "5349b6d57228cb2aeb77e198d6adc93f745e3abb9b4624929b7e29f4a920c0a5"
},
"serialized": "ff011e0100000006000000000000000000023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d380969800000000000002000100000000000000b693449adda7efc015d87944eae8b7c37eb1690a020000000000000027fa7caffaae77ddb9ab232fdbda56d5e5af2393cf4e94776e768110e62961747f39b68993d4ff5ec2171cad2fab6d77babb2ce31181f005876031d43e6d7732770c6aca73b33057c7aad6279cf2da03829a7b62006581c24bbe49e57127604b18d2efdd8d1d2bfe23f9b1e7f15b3f46a647b976e79884b61331546c5844ded781974e181a03a4066f858020fb347ad9628773b465011fb86a8ddbddbed012ff46fc0f3c9a30f3c1544d7a32b9355c318ad453837615e8399f676856c97cf6dcb8d18507ff9c0ffe195d23624e296182477644ed3689023aa80e3663d737716818978ffbae59a8a9f32257a341e1391ca1e0fd744f3382b41e507dca92fa91f98e2024b67938420aaf0c268266dfe4d1f92e81cb3a0421"
}
22 changes: 22 additions & 0 deletions tests/fixtures/transactions/transfer/transfer-multi-sign.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"data": {
"version": 1,
"network": 30,
"typeGroup": 1,
"type": 0,
"nonce": "1",
"senderPublicKey": "023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d3",
"fee": "10000000",
"amount": "1",
"expiration": 0,
"recipientId": "0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A",
"signature": "f25db2b781b79f671b7848284de63f3cb898f9938c0b6203a11cace4aaa4b962eabe9c4a67c207a3f8baea3b4f4cef90a0b67a2bfd84cd61dcc771597f52656d",
"signatures": [
"005afa0050c85a2ac9b34accb0f47c6a9cc9eee831ac713e62e846898d1b75d6a33034680bce95f638c6dfabf8056f8afa9ef73a3c35741234faf01d0a346e3e7d",
"0104bd019e5a6ea9ee5cc41d9f39efe2a2df2cc653369fdfcb56d5219fa282a8368067586748feb2483883c9eca50a5ae73abd7139d4d1885914ed9d5e5c63f8fb",
"02d6af0f5a85a7967d677b2f1f86e00b8ca37facb714467e12810a692d5bcbdfcac4e4c2d4b79a70c7366405339bf84a854308d20cb48652816a9cf37fb3e86e00"
],
"id": "dcb9d29590313cf6e1b53f120e621e34c39e45fce9114272158036cb99be9c89"
},
"serialized": "ff011e0100000000000100000000000000023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d3809698000000000000010000000000000000000000b693449adda7efc015d87944eae8b7c37eb1690af25db2b781b79f671b7848284de63f3cb898f9938c0b6203a11cace4aaa4b962eabe9c4a67c207a3f8baea3b4f4cef90a0b67a2bfd84cd61dcc771597f52656d005afa0050c85a2ac9b34accb0f47c6a9cc9eee831ac713e62e846898d1b75d6a33034680bce95f638c6dfabf8056f8afa9ef73a3c35741234faf01d0a346e3e7d0104bd019e5a6ea9ee5cc41d9f39efe2a2df2cc653369fdfcb56d5219fa282a8368067586748feb2483883c9eca50a5ae73abd7139d4d1885914ed9d5e5c63f8fb02d6af0f5a85a7967d677b2f1f86e00b8ca37facb714467e12810a692d5bcbdfcac4e4c2d4b79a70c7366405339bf84a854308d20cb48652816a9cf37fb3e86e00"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"data": {
"version": 1,
"network": 30,
"typeGroup": 1,
"type": 8,
"nonce": "6",
"senderPublicKey": "023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d3",
"fee": "2500000000",
"amount": "0",
"asset": {
"username": "simple_tx_tester"
},
"signature": "9a74c959d0cd4ad4352292417de3ed8ed0cac9aad390bb5d93a5ef5d2bdbf54dad9bbf690f2079ad397141acd182b6e5c4285bd64b068083431daffd5dbc5b09",
"signatures": [
"003b5b94d80da3d41f514d77a624f26f7a2336c34ce1ec62f06c61635db31b27135a58b9ee705cbaa45addd6e75098833c80935541ccc050199443a3d4c62c7fdd",
"01335feff7cc3d6e3524dd9892e029d2dea77c76afdeb9445bc0d14c587fd922c6c38e3542b978aeb370dc349b4a1221015f33051407f10ca051a1caa2109fc510",
"02fe8b1d0be5a77455b38f9df31a379e1a80bcab4003a225cbf79d426fcd248e03ff5f499a404d879270086e292aa45ac1af979aa9af4a64e4881ec559fc87e779"
],
"id": "ffaead0f6003e125bb2a66169e87efe29c05dedaec71898abfcbc7a1f846f2b3"
},
"serialized": "ff011e0100000008000600000000000000023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d300f9029500000000001073696d706c655f74785f7465737465729a74c959d0cd4ad4352292417de3ed8ed0cac9aad390bb5d93a5ef5d2bdbf54dad9bbf690f2079ad397141acd182b6e5c4285bd64b068083431daffd5dbc5b09003b5b94d80da3d41f514d77a624f26f7a2336c34ce1ec62f06c61635db31b27135a58b9ee705cbaa45addd6e75098833c80935541ccc050199443a3d4c62c7fdd01335feff7cc3d6e3524dd9892e029d2dea77c76afdeb9445bc0d14c587fd922c6c38e3542b978aeb370dc349b4a1221015f33051407f10ca051a1caa2109fc51002fe8b1d0be5a77455b38f9df31a379e1a80bcab4003a225cbf79d426fcd248e03ff5f499a404d879270086e292aa45ac1af979aa9af4a64e4881ec559fc87e779"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"data": {
"version": 1,
"network": 30,
"typeGroup": 1,
"type": 9,
"nonce": "6",
"senderPublicKey": "023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d3",
"fee": "2500000000",
"amount": "0",
"signature": "730f5d46f0ee978f5437899cea0912a87d9854f384a94f3b5b88fbdd527573bb6c6ed13b3da0a695e41efe2b14bafd587db4563b8f29e10f78736959250e8414",
"signatures": [
"00fe3edd3082e95f42177e6f786f22e3df982e1b85446f9291b6effcdbfe311ec7b9d4df7e68a36ddb6afe04564586c9a3c4245d47077bda91c1fda53d294d7317",
"014e0ca11609da9444233dd13a3561c4ac6f779a177389b498749d70076126b1081d6bab0106938b2431c04c8b4cecb78f8d348ba81e7a03eee5f9fc9b0f1a3131",
"023a7826b28719baf87f4a3a5a10b51d2ce26172a01d92d41691edf7630fd5bd51d9ace6fdfa1361c7a0834d6a6017c3fba4f642fcb2a49e251fbcf6464b5256cc"
],
"id": "d0210c375d32eec25ca9513099b98e559c3acb136d08011874149217e17ff8f1"
},
"serialized": "ff011e0100000009000600000000000000023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d300f902950000000000730f5d46f0ee978f5437899cea0912a87d9854f384a94f3b5b88fbdd527573bb6c6ed13b3da0a695e41efe2b14bafd587db4563b8f29e10f78736959250e841400fe3edd3082e95f42177e6f786f22e3df982e1b85446f9291b6effcdbfe311ec7b9d4df7e68a36ddb6afe04564586c9a3c4245d47077bda91c1fda53d294d7317014e0ca11609da9444233dd13a3561c4ac6f779a177389b498749d70076126b1081d6bab0106938b2431c04c8b4cecb78f8d348ba81e7a03eee5f9fc9b0f1a3131023a7826b28719baf87f4a3a5a10b51d2ce26172a01d92d41691edf7630fd5bd51d9ace6fdfa1361c7a0834d6a6017c3fba4f642fcb2a49e251fbcf6464b5256cc"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"data": {
"version": 1,
"network": 30,
"typeGroup": 1,
"type": 2,
"nonce": "0",
"senderPublicKey": "023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d3",
"fee": "2500000000",
"amount": "0",
"asset": {
"validatorPublicKey": "a08058db53e2665c84a40f5152e76dd2b652125a6079130d4c315e728bcf4dd1dfb44ac26e82302331d61977d3141118"
},
"signature": "0604c8ecb42e1cc125da7e88fbb6e8b3c3cb703890701b91f8277bf84493ac4994417e8c090309f8147316091d879a1a3c1ce15a6476e029c6f0597a5cfd3533",
"signatures": [
"00ad621bb19f24c785eded7e3953b575e25fca5b26890eda8ac87cb029d8a28d2c2ef084d98d617fddf7677b27488705e3c5c6d6568a2c44753212e3589e93b89c",
"018de3507e97d8e8e88f77c2cac0c4a7b8767b8527b2a53d81a119e2dbf6672fc8595de1c9ddbb1c88fadf7266923b2289dfbd3b266059c77609bdec52e8efeb61",
"021cbf94035e39cf80b4ccb7ee7d9cfac747ab6e1f73ef4a68b5600ee48c1e94861076718d11ab3908ecc6252c0ea515f6586f966e50842846cce5eada78d84453"
],
"id": "91c5b9e9dd0915a0e2a44edcae3cd0182ffcdcc3921721fc4a88e5b91a3a1d90"
},
"serialized": "ff011e0100000002000000000000000000023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d300f902950000000000a08058db53e2665c84a40f5152e76dd2b652125a6079130d4c315e728bcf4dd1dfb44ac26e82302331d61977d31411180604c8ecb42e1cc125da7e88fbb6e8b3c3cb703890701b91f8277bf84493ac4994417e8c090309f8147316091d879a1a3c1ce15a6476e029c6f0597a5cfd353300ad621bb19f24c785eded7e3953b575e25fca5b26890eda8ac87cb029d8a28d2c2ef084d98d617fddf7677b27488705e3c5c6d6568a2c44753212e3589e93b89c018de3507e97d8e8e88f77c2cac0c4a7b8767b8527b2a53d81a119e2dbf6672fc8595de1c9ddbb1c88fadf7266923b2289dfbd3b266059c77609bdec52e8efeb61021cbf94035e39cf80b4ccb7ee7d9cfac747ab6e1f73ef4a68b5600ee48c1e94861076718d11ab3908ecc6252c0ea515f6586f966e50842846cce5eada78d84453"
}

This file was deleted.

Loading

0 comments on commit 9ae1831

Please sign in to comment.