Skip to content

Commit

Permalink
fix: set network config for proper crypto derivations (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsANameToo committed Jun 4, 2021
1 parent 9e24b40 commit 918194e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/Providers/ExplorerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Providers;

use ArkEcosystem\Crypto\Configuration\Network as NetworkConfiguration;
use App\Contracts\Network;
use App\Services\Blockchain\NetworkFactory;
use Illuminate\Support\ServiceProvider;
Expand All @@ -17,10 +18,15 @@ final class ExplorerServiceProvider extends ServiceProvider
*/
public function register()
{
$network = NetworkFactory::make(config('explorer.network'));

$this->app->singleton(
Network::class,
fn ($app) => NetworkFactory::make($app['config']['explorer']['network'])
fn () => $network
);

// Used for crypto calculations, e.g. multisig address derivation
NetworkConfiguration::set($network->config());
}

/**
Expand Down
43 changes: 43 additions & 0 deletions tests/Unit/ViewModels/TransactionViewModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
use App\Models\Block;
use App\Models\Transaction;
use App\Models\Wallet;
use App\Services\Blockchain\NetworkFactory;
use App\Services\Cache\NetworkCache;
use App\ViewModels\TransactionViewModel;
use App\ViewModels\WalletViewModel;
use ArkEcosystem\Crypto\Configuration\Network as NetworkConfiguration;
use ArkEcosystem\Crypto\Identities\Address;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use function Spatie\Snapshots\assertMatchesSnapshot;
use function Tests\configureExplorerDatabase;
Expand Down Expand Up @@ -793,6 +796,46 @@
expect($this->subject->multiSignatureAddress())->toBeString();
});

it('should derive the correct multisignature address', function () {
expect($this->subject->multiSignatureAddress())->toBeNull();

$this->subject = new TransactionViewModel(Transaction::factory()->create([
'type' => CoreTransactionTypeEnum::MULTI_SIGNATURE,
'type_group' => TransactionTypeGroupEnum::CORE,
'asset' => null,
]));

expect($this->subject->multiSignatureAddress())->toBeNull();

$this->subject = new TransactionViewModel(Transaction::factory()->create([
'type' => CoreTransactionTypeEnum::MULTI_SIGNATURE,
'type_group' => TransactionTypeGroupEnum::CORE,
'asset' => [
'multiSignature' => [
'min' => 3,
'publicKeys' => [
'02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56',
'02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b',
'03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0',
'020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3',
'03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219',
],
],
],
]));

expect($this->subject->multiSignatureAddress())->toBe('DMNBBtYt1teAKxA2BpiTW9PA3gX3Ad5dyk');

Config::set('explorer.network', 'production');

$network = NetworkFactory::make(config('explorer.network'));
NetworkConfiguration::set($network->config());

expect($this->subject->multiSignatureAddress())->toBe('AXzxJ8Ts3dQ2bvBR1tPE7GUee9iSEJb8HX');

Config::set('explorer.network', 'development');
});

it('should get the multi signature minimum', function () {
expect($this->subject->multiSignatureMinimum())->toBeNull();

Expand Down

0 comments on commit 918194e

Please sign in to comment.