Commit f64d1050 authored by Emiliano Balbuena's avatar Emiliano Balbuena

(test): WithdrawEvent spec test

1 merge request!393(feat): Withdrawal status support
Pipeline #95695461 failed with stages
in 2 minutes and 45 seconds
......@@ -6,6 +6,7 @@ use Minds\Core\Blockchain\Transactions\Repository;
use Minds\Core\Blockchain\Transactions\Transaction;
use Minds\Core\Config\Config;
use Minds\Core\Rewards\Withdraw\Manager;
use Minds\Core\Rewards\Withdraw\Request;
use Minds\Core\Util\BigNumber;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
......@@ -31,9 +32,9 @@ class WithdrawEventSpec extends ObjectBehavior
->willReturn([
'contracts' => [
'withdraw' => [
'contract_address' => '0xasd'
]
]
'contract_address' => '0xasd',
],
],
]);
}
......@@ -46,30 +47,54 @@ class WithdrawEventSpec extends ObjectBehavior
{
$this->getTopics()->shouldReturn([
'0x317c0f5ab60805d3e3fb6aaa61ccb77253bbb20deccbbe49c544de4baa4d7f8f',
'blockchain:fail'
'blockchain:fail',
]);
}
public function it_should_complete_withdrawal_on_event()
public function it_should_complete_withdrawal_on_event(
Request $request,
Transaction $transaction
)
{
$this->manager->complete(Argument::that(function ($request) {
return $request->getTx() == '0x62a70ccf3b37b9368efa3dd4785e715139c994ba9957a125e299b14a8eccd00c'
&& $request->getAddress() == '0x177fd9efd24535e73b81e99e7f838cdef265e6cb'
&& $request->getUserGuid() == (string) BigNumber::_('786645648014315523')
&& $request->getGas() == (string) BigNumber::_('67839000000000')
&& $request->getAmount() == (string) BigNumber::_('10000000000000000000');
}), Argument::type('\Minds\Core\Blockchain\Transactions\Transaction'))
$transaction->getTimestamp()
->shouldBeCalled()
->willReturn(123456789);
$request->getAddress()
->shouldBeCalled()
->willReturn('0x177fd9efd24535e73b81e99e7f838cdef265e6cb');
$request->getGas()
->shouldBeCalled()
->willReturn('67839000000000');
$request->getAmount()
->shouldBeCalled()
->willReturn('10000000000000000000');
$this->manager->get(
Argument::that(function (Request $request) {
return (string) $request->getUserGuid() === '786645648014315523' &&
$request->getTimestamp() === 123456789 &&
$request->getTx() === '0x62a70ccf3b37b9368efa3dd4785e715139c994ba9957a125e299b14a8eccd00c';
})
)
->shouldBeCalled()
->willReturn($request);
$this->manager->confirm($request, Argument::type('\Minds\Core\Blockchain\Transactions\Transaction'))
->shouldBeCalled();
$data = "0x000000000000000000000000177fd9efd24535e73b81e99e7f838cdef265e6cb"
. "0000000000000000000000000000000000000000000000000aeaba0c8e001003"
. "00000000000000000000000000000000000000000000000000003db2ff7f3600"
. "0000000000000000000000000000000000000000000000008ac7230489e80000";
$this->onRequest([
'address' => '0xasd',
'data' => $data,
'transactionHash' => '0x62a70ccf3b37b9368efa3dd4785e715139c994ba9957a125e299b14a8eccd00c'
], new Transaction);
'transactionHash' => '0x62a70ccf3b37b9368efa3dd4785e715139c994ba9957a125e299b14a8eccd00c',
], $transaction);
}
public function it_should_send_a_blockchain_fail_event(Transaction $transaction)
......@@ -115,8 +140,8 @@ class WithdrawEventSpec extends ObjectBehavior
'contracts' => [
'withdraw' => [
'contract_address' => '0x277fd9efd24535e73b81e99e7f838cdef265e6cb',
]
]
],
],
]);
$data = "0x000000000000000000000000177fd9efd24535e73b81e99e7f838cdef265e6cb"
......@@ -127,7 +152,7 @@ class WithdrawEventSpec extends ObjectBehavior
->duringOnRequest([
'address' => '0x177fd9efd24535e73b81e99e7f838cdef265e6cb',
'data' => $data,
'transactionHash' => '0x62a70ccf3b37b9368efa3dd4785e715139c994ba9957a125e299b14a8eccd00c'
'transactionHash' => '0x62a70ccf3b37b9368efa3dd4785e715139c994ba9957a125e299b14a8eccd00c',
], (new Transaction())->setContract('withdraw'));
}
}
Please register or to comment