UNPKG

2.59 kBJavaScriptView Raw
1/*
2 * ISC License (ISC)
3 * Copyright 2018 aeternity developers
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
16 */
17
18import { Universal, Crypto, MemoryAccount, Node } from '../../es'
19import chai from 'chai'
20import chaiAsPromised from 'chai-as-promised'
21
22chai.use(chaiAsPromised)
23chai.should()
24
25export const url = process.env.TEST_URL || 'http://localhost:3013'
26export const internalUrl = process.env.TEST_INTERNAL_URL || 'http://localhost:3113'
27export const compilerUrl = process.env.COMPILER_URL || 'http://localhost:3080'
28export const publicKey = process.env.PUBLIC_KEY || 'ak_2dATVcZ9KJU5a8hdsVtTv21pYiGWiPbmVcU1Pz72FFqpk9pSRR'
29const secretKey = process.env.SECRET_KEY || 'bf66e1c256931870908a649572ed0257876bb84e3cdf71efb12f56c7335fad54d5cf08400e988222f26eb4b02c8f89077457467211a6e6d955edb70749c6a33b'
30export const networkId = process.env.TEST_NETWORK_ID || 'ae_devnet'
31const forceCompatibility = process.env.FORCE_COMPATIBILITY || false
32export const genesisAccount = MemoryAccount({ keypair: { publicKey, secretKey } })
33export const account = Crypto.generateKeyPair()
34
35export const BaseAe = async (params = {}) => {
36 const ae = await Universal.waitMined(true).compose({
37 deepProps: { Swagger: { defaults: { debug: !!process.env.DEBUG } } },
38 props: { process, compilerUrl }
39 })({
40 ...params,
41 forceCompatibility,
42 accounts: [...params.accounts || [], genesisAccount],
43 nodes: [{ name: 'test', instance: await Node({ url, internalUrl }) }]
44 })
45 ae.removeAccount(process.env.WALLET_PUB)
46 return ae
47}
48
49const spendPromise = (async () => {
50 const ae = await BaseAe({ networkId })
51 await ae.awaitHeight(2)
52 await ae.spend('1' + '0'.repeat(26), account.publicKey)
53})()
54
55export async function getSdk (nativeMode) {
56 await spendPromise
57
58 return BaseAe({
59 accounts: [MemoryAccount({ keypair: account })],
60 address: account.publicKey,
61 nativeMode,
62 networkId
63 })
64}