diff --git a/database/factories/TransactionFactory.php b/database/factories/TransactionFactory.php index 6ef4d2225..481345ef5 100644 --- a/database/factories/TransactionFactory.php +++ b/database/factories/TransactionFactory.php @@ -11,6 +11,9 @@ use App\Models\Transaction; use App\Models\Wallet; use App\Services\BigNumber; +use ArkEcosystem\Crypto\Enums\AbiFunction; +use ArkEcosystem\Crypto\Enums\ContractAbiType; +use ArkEcosystem\Crypto\Utils\AbiEncoder; use Illuminate\Database\Eloquent\Factories\Factory; use function Tests\faker; @@ -77,12 +80,19 @@ public function tokenTransfer(string $address, int $amount): Factory */ public function multiPayment(array $recipients, array $amounts): Factory { - $method = ContractMethod::multiPayment(); + $pay = []; - $method .= implode('', array_map(fn (string $recipient) => str_pad(preg_replace('/^0x/', '', $recipient), 64, '0', STR_PAD_LEFT), $recipients)); - $method .= implode('', array_map(fn (BigNumber $amount) => str_pad($amount->toHex(), 64, '0', STR_PAD_LEFT), $amounts)); + foreach ($recipients as $index => $recipient) { + $pay[0][] = $recipient; + $pay[1][] = $amounts[$index]->__toString(); + } - return $this->withPayload($method) + $payload = (new AbiEncoder(ContractAbiType::MULTIPAYMENT)) + ->encodeFunctionCall(AbiFunction::MULTIPAYMENT->value, $pay); + + $payload = preg_replace('/^0x/', '', $payload); + + return $this->withPayload($payload) ->state(fn () => [ 'recipient_address' => Network::knownContract('multipayment'), ]); diff --git a/tests/Unit/ViewModels/TransactionViewModelTest.php b/tests/Unit/ViewModels/TransactionViewModelTest.php index 4b432b433..928758d3c 100644 --- a/tests/Unit/ViewModels/TransactionViewModelTest.php +++ b/tests/Unit/ViewModels/TransactionViewModelTest.php @@ -7,6 +7,7 @@ use App\Models\Receipt; use App\Models\Transaction; use App\Models\Wallet; +use App\Services\BigNumber; use App\Services\Cache\CryptoDataCache; use App\Services\Cache\NetworkCache; use App\ViewModels\TransactionViewModel; @@ -315,8 +316,15 @@ it('should get formatted multi payment receipts', function () { $transaction = new TransactionViewModel(Transaction::factory() - ->withPayload('084ce708000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b693449adda7efc015d87944eae8b7c37eb1690a000000000000000000000000b693449adda7efc015d87944eae8b7c37eb1690a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000000000000000000000000000000000000bebc200') - ->create()); + ->multiPayment([ + '0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A', + '0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A', + '0xEd0C906b8fcCDe71A19322DFfe929c6e04460cFF', + ], [ + BigNumber::new(100000000), + BigNumber::new(200000000), + BigNumber::new(1234567), + ])->create()); expect($transaction->multiPaymentRecipients())->toEqual([ '0' => [ @@ -327,6 +335,10 @@ 'address' => '0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A', 'amount' => '200000000', ], + '2' => [ + 'address' => '0xEd0C906b8fcCDe71A19322DFfe929c6e04460cFF', + 'amount' => '1234567', + ], ]); });