-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8391bed
commit 5fbd82e
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* global describe, expect, test */ | ||
const sandbox = require('sinon').createSandbox() | ||
|
||
const { QuantityNotAllowedError, TransactionNotMinedError } = require('../../../index').utils.errors | ||
|
||
const { Erc20TokenServiceBuilder, TradingWalletServiceBuilder } = require('../../../index').factories | ||
const { TradingWalletFacade } = require('../../../index').facades | ||
|
||
const tokenAddress = '0x9727e2fb13f7f42d5a6f1a4a9877d4a7e0404d6a' | ||
const personalWalletAddress = '0xcf4b07a79b5d29988f488f30c4a676ecaad35c02' | ||
const tradingWalletAddress = '0x9c6d1840381cc570235a4ed867bf8465e32ce753' | ||
const privateKey = '0x4c7ee440ad699493b22732031e4a3277d2d8aa834b727aa0b358e3310aa37384' | ||
const quantityToDeposit = '500000000000000000' | ||
|
||
const erc20TokenServiceBuilder = new Erc20TokenServiceBuilder(tokenAddress) | ||
const tradingWalletFacade = new TradingWalletFacade( | ||
TradingWalletServiceBuilder.build(), | ||
erc20TokenServiceBuilder.build(), | ||
) | ||
|
||
afterEach(() => { | ||
sandbox.restore() | ||
}) | ||
|
||
describe('DepositTokenAsync', () => { | ||
const approvedTxHash = '0xApprovedTxHash' | ||
test('should raise TransactionNotMinedError if the approved transaction was not mined.', async () => { | ||
sandbox.stub(tradingWalletFacade.erc20TokenService, 'approveTrasferAsync').returns(approvedTxHash) | ||
const isApprovedMinedMock = sandbox.stub(tradingWalletFacade.transactionLib, 'isTransactionMined') | ||
isApprovedMinedMock.onFirstCall().returns(false) | ||
|
||
return expect(tradingWalletFacade.depositTokenAsync( | ||
personalWalletAddress, | ||
tradingWalletAddress, | ||
quantityToDeposit, | ||
tokenAddress, | ||
privateKey, | ||
)).rejects.toBeInstanceOf(TransactionNotMinedError) | ||
}) | ||
|
||
test('should raise TransactionNotMinedError if deposit transaction was not mined.', async () => { | ||
sandbox.stub(tradingWalletFacade.erc20TokenService, 'approveTrasferAsync').returns(approvedTxHash) | ||
const isApprovedMinedMock = sandbox.stub(tradingWalletFacade.transactionLib, 'isTransactionMined') | ||
isApprovedMinedMock.onFirstCall().returns(true) | ||
sandbox.stub(tradingWalletFacade.erc20TokenService, 'getAllowanceAsync').returns(quantityToDeposit + 10000) | ||
|
||
return expect(tradingWalletFacade.depositTokenAsync( | ||
personalWalletAddress, | ||
tradingWalletAddress, | ||
quantityToDeposit, | ||
tokenAddress, | ||
privateKey, | ||
)).rejects.toBeInstanceOf(QuantityNotAllowedError) | ||
}) | ||
}) |