@ -1,4 +1,5 @@
import { strict as assert } from 'assert' ;
import { strict as assert } from 'assert' ;
import nock from 'nock' ;
import {
import {
KOVAN _CHAIN _ID ,
KOVAN _CHAIN _ID ,
MAINNET _CHAIN _ID ,
MAINNET _CHAIN _ID ,
@ -8,52 +9,68 @@ import {
import { TRANSAK _API _KEY } from '../constants/on-ramp' ;
import { TRANSAK _API _KEY } from '../constants/on-ramp' ;
import getBuyEthUrl from './buy-eth-url' ;
import getBuyEthUrl from './buy-eth-url' ;
describe ( 'buy-eth-url' , function ( ) {
const WYRE _ACCOUNT _ID = 'AC-7AG3W4XH4N2' ;
const mainnet = {
const ETH _ADDRESS = '0x0dcd5d886577d5581b0c524242ef2ee70be3e7bc' ;
const MAINNET = {
chainId : MAINNET _CHAIN _ID ,
chainId : MAINNET _CHAIN _ID ,
amount : 5 ,
amount : 5 ,
address : '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc' ,
address : ETH _ADDRESS ,
} ;
} ;
const ropsten = {
const ROPSTEN = {
chainId : ROPSTEN _CHAIN _ID ,
chainId : ROPSTEN _CHAIN _ID ,
} ;
} ;
const rinkeby = {
const RINKEBY = {
chainId : RINKEBY _CHAIN _ID ,
chainId : RINKEBY _CHAIN _ID ,
} ;
} ;
const kovan = {
const KOVAN = {
chainId : KOVAN _CHAIN _ID ,
chainId : KOVAN _CHAIN _ID ,
} ;
} ;
describe ( 'buy-eth-url' , function ( ) {
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 Wyre url with an ETH address for Ethereum mainnet' , function ( ) {
it ( 'returns a fallback Wyre url if /orders/reserve API call fails' , async function ( ) {
const wyreUrl = getBuyEthUrl ( mainnet ) ;
const wyreUrl = await getBuyEthUrl ( MAINNET ) ;
assert . equal (
assert . equal (
wyreUrl ,
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 ( ) {
it ( 'returns Transak url with an ETH address for Ethereum mainnet' , async function ( ) {
const transakUrl = getBuyEthUrl ( { ... mainnet , service : 'transak' } ) ;
const transakUrl = await getBuyEthUrl ( { ... MAINNET , service : 'transak' } ) ;
assert . equal (
assert . equal (
transakUrl ,
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 ( ) {
it ( 'returns metamask ropsten faucet for network 3' , async function ( ) {
const ropstenUrl = getBuyEthUrl ( ropsten ) ;
const ropstenUrl = await getBuyEthUrl ( ROPSTEN ) ;
assert . equal ( ropstenUrl , 'https://faucet.metamask.io/' ) ;
assert . equal ( ropstenUrl , 'https://faucet.metamask.io/' ) ;
} ) ;
} ) ;
it ( 'returns rinkeby dapp for network 4' , function ( ) {
it ( 'returns rinkeby dapp for network 4' , async function ( ) {
const rinkebyUrl = getBuyEthUrl ( rinkeby ) ;
const rinkebyUrl = await getBuyEthUrl ( RINKEBY ) ;
assert . equal ( rinkebyUrl , 'https://www.rinkeby.io/' ) ;
assert . equal ( rinkebyUrl , 'https://www.rinkeby.io/' ) ;
} ) ;
} ) ;
it ( 'returns kovan github test faucet for network 42' , function ( ) {
it ( 'returns kovan github test faucet for network 42' , async function ( ) {
const kovanUrl = getBuyEthUrl ( kovan ) ;
const kovanUrl = await getBuyEthUrl ( KOVAN ) ;
assert . equal ( kovanUrl , 'https://github.com/kovan-testnet/faucet' ) ;
assert . equal ( kovanUrl , 'https://github.com/kovan-testnet/faucet' ) ;
} ) ;
} ) ;
} ) ;
} ) ;