Skip to content

Commit

Permalink
Merge pull request #1037 from aeternity/feature/make-tests-configs-mo…
Browse files Browse the repository at this point in the history
…re-flexible

Make tests configuration more flexible
  • Loading branch information
davidyuk committed Jul 3, 2020
2 parents b00d781 + e91f4ac commit a10f340
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docker/accounts_test.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi": 100000000000001000000000000000000000
"ak_2dATVcZ9KJU5a8hdsVtTv21pYiGWiPbmVcU1Pz72FFqpk9pSRR": 100000000000001000000000000000000000
}
6 changes: 3 additions & 3 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import Compiler from '../../es/contract/compiler'
import { describe, it, before } from 'mocha'
import { BaseAe, configure, plan, ready, compilerUrl } from './'
import { BaseAe, configure, plan, ready, compilerUrl, publicKey } from './'
import { decode } from '../../es/tx/builder/helpers'

import * as R from 'ramda'
Expand Down Expand Up @@ -56,7 +56,7 @@ namespace Test =
contract Voting =
type test_type = int
type test_type = int
record state = { value: string, key: test_type, testOption: option(string) }
record test_record = { value: string, key: list(test_type) }
entrypoint test : () => int
Expand Down Expand Up @@ -381,7 +381,7 @@ describe('Contract', function () {

it('Dry-run without accounts', async () => {
const client = await BaseAe()
client.removeAccount('ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi')
client.removeAccount(publicKey)
client.addresses().length.should.be.equal(0)
const address = await client.address().catch(e => false)
address.should.be.equal(false)
Expand Down
30 changes: 18 additions & 12 deletions test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

import { Universal as Ae } from '../../es/ae/universal'
import { Universal } from '../../es/ae/universal'
import * as Crypto from '../../es/utils/crypto'
import { BigNumber } from 'bignumber.js'
import MemoryAccount from '../../es/account/memory'
Expand All @@ -28,21 +28,27 @@ chai.should()
export const url = process.env.TEST_URL || 'http://localhost:3013'
export const internalUrl = process.env.TEST_INTERNAL_URL || 'http://localhost:3113'
export const compilerUrl = process.env.COMPILER_URL || 'http://localhost:3080'
export const publicKey = process.env.PUBLIC_KEY || 'ak_2dATVcZ9KJU5a8hdsVtTv21pYiGWiPbmVcU1Pz72FFqpk9pSRR';
const secretKey = process.env.SECRET_KEY || 'bf66e1c256931870908a649572ed0257876bb84e3cdf71efb12f56c7335fad54d5cf08400e988222f26eb4b02c8f89077457467211a6e6d955edb70749c6a33b';
export const networkId = process.env.TEST_NETWORK_ID || 'ae_devnet'
export const forceCompatibility = process.env.FORCE_COMPATIBILITY || false
export const genesisAccount = MemoryAccount({ keypair: { publicKey, secretKey } })
export const account = Crypto.generateKeyPair()
export const account2 = Crypto.generateKeyPair()

export const BaseAe = async (params) => Ae.waitMined(true).compose({
deepProps: { Swagger: { defaults: { debug: !!process.env['DEBUG'] } } },
props: { process, compilerUrl }
})({
...params,
forceCompatibility,
nodes: [{ name: 'test', instance: await Node({ url, internalUrl }) }]
})

const BaseAeWithAccounts = BaseAe
export const BaseAe = async (params = {}) => {
const ae = await Universal.waitMined(true).compose({
deepProps: { Swagger: { defaults: { debug: !!process.env['DEBUG'] } } },
props: { process, compilerUrl }
})({
...params,
forceCompatibility,
accounts: [...params.accounts || [], genesisAccount],
nodes: [{ name: 'test', instance: await Node({ url, internalUrl }) }]
})
ae.removeAccount(process.env.WALLET_PUB)
return ae
}

let planned = BigNumber(0)
let charged = false
Expand Down Expand Up @@ -71,7 +77,7 @@ export async function ready (mocha, native = true, withAccounts = false) {
charged = true
}

return BaseAeWithAccounts({
return BaseAe({
accounts: [MemoryAccount({ keypair: account }), MemoryAccount({ keypair: account2 })],
address: account.publicKey,
nativeMode: native,
Expand Down
17 changes: 10 additions & 7 deletions test/integration/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

import { Aepp, Wallet, Node, RpcWallet, RpcAepp } from '../../es'
import { compilerUrl, getFakeConnections, url, internalUrl, networkId } from './'
import { Aepp, Wallet, Node, RpcWallet, RpcAepp, MemoryAccount } from '../../es'
import { compilerUrl, getFakeConnections, url, internalUrl, networkId, publicKey, genesisAccount } from './'

import { describe, it, before } from 'mocha'
import BrowserWindowMessageConnection from '../../es/utils/aepp-wallet-communication/connection/browser-window-message'
import { generateKeyPair, verify } from '../../es/utils/crypto'
import { decode } from '../../es/tx/builder/helpers'
import { unpackTx } from '../../es/tx/builder'
import MemoryAccount from '../../es/account/memory'
import {
getBrowserAPI,
getHandler,
Expand Down Expand Up @@ -61,6 +60,7 @@ describe('Aepp<->Wallet', function () {
before(async () => {
wallet = await RpcWallet({
compilerUrl: compilerUrl,
accounts: [genesisAccount],
nodes: [{ name: 'local', instance: node }],
name: 'Wallet',
onConnection (aepp, { accept, deny }) {
Expand All @@ -77,6 +77,7 @@ describe('Aepp<->Wallet', function () {
this.shareWalletInfo(connectionFromWalletToAepp.sendMessage.bind(connectionFromWalletToAepp))
}
})
wallet.removeAccount(process.env.WALLET_PUB)
aepp = await RpcAepp({
name: 'AEPP',
nodes: [{ name: 'test', instance: node }],
Expand Down Expand Up @@ -187,7 +188,7 @@ describe('Aepp<->Wallet', function () {
subscriptionResponse.subscription.should.be.an('array')
subscriptionResponse.subscription.filter(e => e === 'connected').length.should.be.equal(1)
subscriptionResponse.address.current.should.be.an('object')
Object.keys(subscriptionResponse.address.current)[0].should.be.equal('ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi')
Object.keys(subscriptionResponse.address.current)[0].should.be.equal(publicKey)
subscriptionResponse.address.connected.should.be.an('object')
Object.keys(subscriptionResponse.address.connected).length.should.be.equal(1)
})
Expand All @@ -200,7 +201,7 @@ describe('Aepp<->Wallet', function () {
}
})
it('Get address: subscribed for accounts', async () => {
(await aepp.address()).should.be.equal('ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi')
(await aepp.address()).should.be.equal(publicKey)
})
it('Ask for address: subscribed for accounts -> wallet deny', async () => {
wallet.onAskAccounts = (aepp, actions) => {
Expand All @@ -219,7 +220,7 @@ describe('Aepp<->Wallet', function () {
}
const addressees = await aepp.askAddresses()
addressees.length.should.be.equal(2)
addressees[0].should.be.equal('ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi')
addressees[0].should.be.equal(publicKey)
})
it('Not authorize', async () => {
const rpcClients = wallet.getClients()
Expand Down Expand Up @@ -556,9 +557,11 @@ describe('Aepp<->Wallet', function () {
connections = getConnections(true)
wallet = await Wallet({
compilerUrl,
accounts: [genesisAccount],
nodes: [{ name: 'test', instance: node }],
self: connections.waelletConnection
})
wallet.removeAccount(process.env.WALLET_PUB)
aepp = await Aepp({ parent: Object.assign({}, connections.aeppConnection), self: connections.aeppConnection })
})
it('Call wallet method without guards', async () => {
Expand All @@ -576,7 +579,7 @@ describe('Aepp<->Wallet', function () {
return true
}
const address = await aepp.address()
address.should.be.equal('ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi')
address.should.be.equal(publicKey)
})
it('Reject address retrieving', async () => {
wallet.onAccount = (m, p, s) => false
Expand Down

0 comments on commit a10f340

Please sign in to comment.