@ -1,4 +1,5 @@
import { strict as assert } from 'assert' ;
import nock from 'nock' ;
import {
KOVAN _CHAIN _ID ,
MAINNET _CHAIN _ID ,
@ -8,52 +9,68 @@ import {
import { TRANSAK _API _KEY } from '../constants/on-ramp' ;
import getBuyEthUrl from './buy-eth-url' ;
const WYRE _ACCOUNT _ID = 'AC-7AG3W4XH4N2' ;
const ETH _ADDRESS = '0x0dcd5d886577d5581b0c524242ef2ee70be3e7bc' ;
const MAINNET = {
chainId : MAINNET _CHAIN _ID ,
amount : 5 ,
address : ETH _ADDRESS ,
} ;
const ROPSTEN = {
chainId : ROPSTEN _CHAIN _ID ,
} ;
const RINKEBY = {
chainId : RINKEBY _CHAIN _ID ,
} ;
const KOVAN = {
chainId : KOVAN _CHAIN _ID ,
} ;
describe ( 'buy-eth-url' , function ( ) {
const mainnet = {
chainId : MAINNET _CHAIN _ID ,
amount : 5 ,
address : '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc' ,
} ;
const ropsten = {
chainId : ROPSTEN _CHAIN _ID ,
} ;
const rinkeby = {
chainId : RINKEBY _CHAIN _ID ,
} ;
const kovan = {
chainId : KOVAN _CHAIN _ID ,
} ;
it ( 'returns Wyre url with an ETH address for Ethereum mainnet' , function ( ) {
const wyreUrl = getBuyEthUrl ( mainnet ) ;
it ( 'returns Wyre url with an ETH address for Ethereum mainnet' , async function ( ) {
nock ( 'https://api.metaswap.codefi.network' )
. get ( ` /fiatOnRampUrl?serviceName=wyre&destinationAddress= ${ ETH _ADDRESS } ` )
. reply ( 200 , {
url : ` https://pay.sendwyre.com/purchase?accountId= ${ WYRE _ACCOUNT _ID } &utm_campaign= ${ WYRE _ACCOUNT _ID } &destCurrency=ETH&utm_medium=widget&paymentMethod=debit-card&reservation=MLZVUF8FMXZUMARJC23B&dest=ethereum%3A ${ ETH _ADDRESS } &utm_source=checkout ` ,
} ) ;
const wyreUrl = await getBuyEthUrl ( MAINNET ) ;
assert . equal (
wyreUrl ,
` https://pay.sendwyre.com/purchase?accountId= ${ WYRE _ACCOUNT _ID } &utm_campaign= ${ WYRE _ACCOUNT _ID } &destCurrency=ETH&utm_medium=widget&paymentMethod=debit-card&reservation=MLZVUF8FMXZUMARJC23B&dest=ethereum%3A ${ ETH _ADDRESS } &utm_source=checkout ` ,
) ;
nock . cleanAll ( ) ;
} ) ;
it ( 'returns a fallback Wyre url if /orders/reserve API call fails' , async function ( ) {
const wyreUrl = await getBuyEthUrl ( MAINNET ) ;
assert . equal (
wyreUrl ,
'https://pay.sendwyre.com/purchase?dest=ethereum:0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc&destCurrency=ETH&accountId=AC-7AG3W4XH4N2&paymentMethod=debit-card' ,
` https://pay.sendwyre.com/purchase?dest=ethereum: ${ ETH _ADDRESS } &destCurrency=ETH&accountId= ${ WYRE _ACCOUNT _ID } &paymentMethod=debit-card ` ,
) ;
} ) ;
it ( 'returns Transak url with an ETH address for Ethereum mainnet' , function ( ) {
const transakUrl = getBuyEthUrl ( { ... mainnet , service : 'transak' } ) ;
it ( 'returns Transak url with an ETH address for Ethereum mainnet' , async function ( ) {
const transakUrl = await getBuyEthUrl ( { ... MAINNET , service : 'transak' } ) ;
assert . equal (
transakUrl ,
` https://global.transak.com/?apiKey= ${ TRANSAK _API _KEY } &hostURL=https%3A%2F%2Fmetamask.io&defaultCryptoCurrency=ETH&walletAddress=0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc ` ,
` https://global.transak.com/?apiKey= ${ TRANSAK _API _KEY } &hostURL=https%3A%2F%2Fmetamask.io&defaultCryptoCurrency=ETH&walletAddress= ${ ETH _ADDRESS } ` ,
) ;
} ) ;
it ( 'returns metamask ropsten faucet for network 3' , function ( ) {
const ropstenUrl = getBuyEthUrl ( ropsten ) ;
it ( 'returns metamask ropsten faucet for network 3' , async function ( ) {
const ropstenUrl = await getBuyEthUrl ( ROPSTEN ) ;
assert . equal ( ropstenUrl , 'https://faucet.metamask.io/' ) ;
} ) ;
it ( 'returns rinkeby dapp for network 4' , function ( ) {
const rinkebyUrl = getBuyEthUrl ( rinkeby ) ;
it ( 'returns rinkeby dapp for network 4' , async function ( ) {
const rinkebyUrl = await getBuyEthUrl ( RINKEBY ) ;
assert . equal ( rinkebyUrl , 'https://www.rinkeby.io/' ) ;
} ) ;
it ( 'returns kovan github test faucet for network 42' , function ( ) {
const kovanUrl = getBuyEthUrl ( kovan ) ;
it ( 'returns kovan github test faucet for network 42' , async function ( ) {
const kovanUrl = await getBuyEthUrl ( KOVAN ) ;
assert . equal ( kovanUrl , 'https://github.com/kovan-testnet/faucet' ) ;
} ) ;
} ) ;