-
Notifications
You must be signed in to change notification settings - Fork 8
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
908a022
commit d71ad81
Showing
3 changed files
with
148 additions
and
19 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
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
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,98 @@ | ||
import { ChainId, CrosschainQuote, EthereumAddress, Source } from '../../src'; | ||
import { | ||
decodeERC20TransferToData, | ||
extractDestinationAddress, | ||
} from '../../src/utils/sanity_check'; | ||
|
||
const okERC20Data = | ||
'0xa9059cbb000000000000000000000000f70da97812cb96acdf810712aa562db8dfa3dbef0000000000000000000000000000000000000000000000056bc75e2d631000000085078f'; | ||
|
||
function getQuote( | ||
chainID: ChainId, | ||
source: Source | undefined = undefined, | ||
to: string | undefined = undefined, | ||
sellTokenAddress: string | undefined = undefined, | ||
data: string | undefined = undefined | ||
): CrosschainQuote { | ||
return { | ||
buyAmount: '', | ||
buyAmountDisplay: '', | ||
buyAmountInEth: '', | ||
buyAmountMinusFees: '', | ||
buyTokenAddress: '' as EthereumAddress, | ||
chainId: chainID, | ||
data: data, | ||
fee: '', | ||
feeInEth: '', | ||
feePercentageBasisPoints: 0, | ||
from: '', | ||
fromAsset: { | ||
address: '', | ||
chainAgnosticId: chainID, | ||
chainId: chainID, | ||
decimals: 18, | ||
icon: '', | ||
logoURI: '', | ||
name: '', | ||
symbol: '', | ||
}, | ||
fromChainId: chainID, | ||
refuel: null, | ||
routes: [], | ||
sellAmount: '', | ||
sellAmountDisplay: '', | ||
sellAmountInEth: '', | ||
sellAmountMinusFees: '', | ||
sellTokenAddress: sellTokenAddress as EthereumAddress, | ||
source: source, | ||
to: to, | ||
toAsset: { | ||
address: '', | ||
chainAgnosticId: chainID, | ||
chainId: chainID, | ||
decimals: 18, | ||
icon: '', | ||
logoURI: '', | ||
name: '', | ||
symbol: '', | ||
}, | ||
toChainId: 0, | ||
tradeAmountUSD: 0, | ||
}; | ||
} | ||
|
||
describe('getToAddressFromCrosschainQuote', () => { | ||
it('should return undefined if non defined source', () => { | ||
const quote = getQuote(1, undefined, '0x1234'); | ||
expect(extractDestinationAddress(quote)).toBeUndefined(); | ||
}); | ||
it('should just use to address for socket', () => { | ||
const quote = getQuote(1, Source.CrosschainAggregatorSocket, '0x1234'); | ||
expect(extractDestinationAddress(quote)).toEqual('0x1234'); | ||
}); | ||
}); | ||
|
||
describe('decodeERC20TransferData', () => { | ||
it('should correctly decode valid ERC20 transfer data', () => { | ||
expect(decodeERC20TransferToData(okERC20Data)).toEqual( | ||
'0xf70da97812cb96acdf810712aa562db8dfa3dbef' | ||
); | ||
}); | ||
it('should return null for invalid data', () => { | ||
const data = '0xdeadbeef'; | ||
expect(decodeERC20TransferToData(data)).toBeUndefined(); | ||
}); | ||
it('should return null for incomplete data', () => { | ||
const data = | ||
'0xa9059cbb000000000000000000000000f70da97812cb96acdf810712aa562db8dfa3dbef'; | ||
expect(decodeERC20TransferToData(data)).toBeUndefined(); | ||
}); | ||
|
||
it('should return decode erc20 data', () => { | ||
const data = | ||
'0xa9059cbb000000000000000000000000f70da97812cb96acdf810712aa562db8dfa3dbef000000000000000000000000000000000000000000000001a055690d9db8000000878469'; | ||
expect(decodeERC20TransferToData(data)).toEqual( | ||
`0xf70da97812cb96acdf810712aa562db8dfa3dbef` | ||
); | ||
}); | ||
}); |