Skip to content

Commit

Permalink
feat(Tests): Fix Breaking Changes and adjust tests (#126)
Browse files Browse the repository at this point in the history
* Fix linter

* feat(index): Adjust SDK initialization in utils and test's
Refactor all BREAKING CAHNGES related to SDK init and account management
Fix `account` module test's
Remove deprecated Jenkins config files and relateds docker config
Fix `.env`

* feat(Account): Add new options `-D --denomination <value=aettos>` to `account spend` and `account transfer` command

* feat(Account): add test's for spend/transfer denomination feature

* build(CI): add Travis config file
  • Loading branch information
nduchak committed Apr 1, 2020
1 parent 1c57538 commit 60b7910
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TAG=v5.5.0
NODE_TAG=v5.5.0
COMPILER_TAG=v4.2.0
57 changes: 57 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
branches:
only:
- master
- develop

dist: xenial

addons:
apt:
packages:
- build-essential
- curl
- libltdl7
- git

services:
- docker

language: node_js
node_js: '10'

cache:
timeout: 604800 # 7 days
directories:
- "$HOME/.npm"

env:
global:
- TEST_NODE=http://localhost:3013
- TEST_URL=http://localhost:3013
- TEST_DEBUG_URL=http://localhost:3113
- TEST_WS_URL=ws://localhost:3014/channel
- TEST_NETWORK_ID=ae_devnet
- COMPILER_URL=http://localhost:3080
- FORCE_COMPATIBILITY=false

before_install:
- docker-compose up -d node compiler

install:
- npm ci

jobs:
include:
- stage: Tests
if: type != "cron"
name: Test
script:
- npm run test
- stage: Tests
if: type = "cron"
env:
- NODE_TAG=master
- COMPILER_TAG=latest
- FORCE_COMPATIBILITY=true
script:
- npm run test
49 changes: 0 additions & 49 deletions Jenkinsfile

This file was deleted.

2 changes: 2 additions & 0 deletions bin/aecli-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ program
.option('-F, --fee [fee]', 'Spend transaction fee.')
.option('-T, --ttl [ttl]', 'Validity of the spend transaction in number of blocks (default forever)', utils.constant.TX_TTL)
.option('-N, --nonce [nonce]', 'Override the nonce that the transaction is going to be sent with')
.option('-D, --denomination [denomination]', 'Denomination of amount', utils.constant.DENOMINATION)
.action(async (walletPath, receiverIdOrName, amount, ...arguments) => await Account.spend(walletPath, receiverIdOrName, amount, utils.cli.getCmdFromArguments(arguments)))


Expand All @@ -73,6 +74,7 @@ program
.option('-F, --fee [fee]', 'Spend transaction fee.')
.option('-T, --ttl [ttl]', 'Validity of the spend transaction in number of blocks (default forever)', utils.constant.TX_TTL)
.option('-N, --nonce [nonce]', 'Override the nonce that the transaction is going to be sent with')
.option('-D, --denomination [denomination]', 'Denomination of amount', utils.constant.DENOMINATION)
.action(async (walletPath, receiver, percentage, ...arguments) => await Account.transferFunds(walletPath, receiver, percentage, utils.cli.getCmdFromArguments(arguments)))


Expand Down
5 changes: 3 additions & 2 deletions bin/commands/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

import { generateKeyPair } from '@aeternity/aepp-sdk/es/utils/crypto'
import { AE_AMOUNT_FORMATS } from '@aeternity/aepp-sdk/es/utils/amount-formatter'

import { generateSecureWallet, generateSecureWalletFromPrivKey } from '../utils/account'
import { HASH_TYPES } from '../utils/constant'
Expand Down Expand Up @@ -63,13 +64,13 @@ async function sign (walletPath, tx, options) {
// ## `Spend` function
// this function allow you to `send` token's to another `account`
async function spend (walletPath, receiverNameOrAddress, amount, options) {
const { ttl, json, nonce, fee, payload = '' } = options
const { ttl, json, nonce, fee, payload = '', denomination = AE_AMOUNT_FORMATS.AETTOS } = options
try {
// Get `keyPair` by `walletPath`, decrypt using password and initialize `Ae` client with this `keyPair`
const client = await initClientByWalletFile(walletPath, options)

await handleApiError(async () => {
let tx = await client.spend(amount, receiverNameOrAddress, { ttl, nonce, payload, fee })
let tx = await client.spend(amount, receiverNameOrAddress, { ttl, nonce, payload, fee, denomination })
// if waitMined false
if (typeof tx !== 'object') {
tx = await client.tx(tx)
Expand Down
23 changes: 19 additions & 4 deletions bin/utils/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import * as R from 'ramda'

import Ae from '@aeternity/aepp-sdk/es/ae/universal'
import Node from '@aeternity/aepp-sdk/es/node'
import Tx from '@aeternity/aepp-sdk/es/tx/tx'
import TxBuilder from '@aeternity/aepp-sdk/es/tx/builder'
import Chain from '@aeternity/aepp-sdk/es/chain/node'
Expand All @@ -35,20 +36,34 @@ export function getCmdFromArguments (args) {
}

// Create `Ae` client
export async function initClient ({ url, keypair, internalUrl, compilerUrl, force: forceCompatibility, native: nativeMode = true, networkId, accounts }) {
return Ae({ url, process, keypair, internalUrl, compilerUrl, forceCompatibility, nativeMode, networkId, accounts })
export async function initClient ({ url, keypair, internalUrl, compilerUrl, force: forceCompatibility, native: nativeMode = true, networkId, accounts = [] }) {
return Ae({
nodes: [{ name: 'test-node', instance: await Node({ url, internalUrl, forceCompatibility }) }],
process,
internalUrl,
compilerUrl,
nativeMode,
networkId,
accounts: [...keypair ? [Account({ keypair })] : [], ...accounts]
})
}
// Create `TxBuilder` client
export async function initTxBuilder ({ url, internalUrl, force: forceCompatibility, native: nativeMode = true, showWarning = true }) {
return Tx({ url, internalUrl, forceCompatibility, nativeMode, showWarning })
return Tx({
nodes: [{ name: 'test-node', instance: await Node({ url, internalUrl, forceCompatibility }) }],
nativeMode,
showWarning
})
}
// Create `OfflineTxBuilder` client
export function initOfflineTxBuilder () {
return TxBuilder
}
// Create `Chain` client
export async function initChain ({ url, internalUrl, force: forceCompatibility }) {
return Chain({ url, internalUrl, forceCompatibility })
return Chain({
nodes: [{ name: 'test-node', instance: await Node({ url, internalUrl, forceCompatibility }) }]
})
}

// Create `Chain` client
Expand Down
3 changes: 3 additions & 0 deletions bin/utils/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// That script contains default configuration for `CLI`

import { ABI_VERSIONS, VM_TYPE, VM_VERSIONS, MIN_GAS_PRICE } from '@aeternity/aepp-sdk/es/tx/builder/schema'
import { AE_AMOUNT_FORMATS } from '@aeternity/aepp-sdk/es/utils/amount-formatter'

export {
// ## AENS
Expand Down Expand Up @@ -79,3 +80,5 @@ export const DEFAULT_CONTRACT_PARAMS = { vmVersion: VM_VERSION, amount: AMOUNT,

// ## DEFAULT OUTPUT FORMAT
export const OUTPUT_JSON = false
// ## AMOUNT FORMAT
export const DENOMINATION = AE_AMOUNT_FORMATS.AETTOS
20 changes: 3 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
version: '3'
services:
sdk:
build:
context: .
dockerfile: Dockerfile.ci
depends_on: [node, compiler]
entrypoint: docker/wait-for-it.sh node:3013 --
env_file: [./docker/sdk.env]
environment:
- WALLET_PRIV=${WALLET_PRIV}
- WALLET_PUB=${WALLET_PUB}
volumes:
- .:/app
- .:/node_modules/@aeternity/aepp-sdk

node:
image: aeternity/aeternity:${TAG}
image: aeternity/aeternity:${NODE_TAG}
hostname: node
expose: [3013, 3113, 3014, 3114]
ports: ["3013:3013", "3113:3113", "3014:3014", "3114:3114"]
environment:
EPOCH_CONFIG: /home/aeternity/aeternity_node.yaml
command: bin/aeternity console -noinput -aecore expected_mine_rate ${EPOCH_MINE_RATE:-5000}
Expand All @@ -32,7 +18,7 @@ services:
compiler:
image: aeternity/aesophia_http:${COMPILER_TAG}
hostname: compiler
expose: [3080]
ports: ["3080:3080"]

volumes:
node_db:
Expand Down
22 changes: 17 additions & 5 deletions test/cli/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
*/

import fs from 'fs'
import { before, describe, it } from 'mocha'
import { after, before, describe, it } from 'mocha'
import { AE_AMOUNT_FORMATS, formatAmount } from '@aeternity/aepp-sdk/es/utils/amount-formatter'
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory'
import { generateKeyPair } from '@aeternity/aepp-sdk/es/utils/crypto'

import { configure, plan, ready, execute, BaseAe, KEY_PAIR, WALLET_NAME } from './index'
import { generateKeyPair } from '@aeternity/aepp-sdk/es/utils/crypto'

const walletName = 'test.wallet'

plan(1000000000)

describe('CLI Account Module', function () {
describe.only('CLI Account Module', function () {
configure(this)

let wallet
Expand Down Expand Up @@ -83,13 +85,23 @@ describe('CLI Account Module', function () {
const amount = 100
const receiverKeys = generateKeyPair()
const receiver = await BaseAe()
receiver.setKeypair(receiverKeys)
await receiver.addAccount(MemoryAccount({ keypair: receiverKeys }), { select: true })

// send coins
await execute(['account', 'spend', WALLET_NAME, '--password', 'test', await receiver.address(), amount], { withOutReject: true, withNetworkId: true })
const receiverBalance = await receiver.balance(await receiver.address())
const receiverBalance = await receiver.getBalance(await receiver.address())
await parseInt(receiverBalance).should.equal(amount)
})
it('Spend coins to another wallet using denomination', async () => {
const amount = 1 // 1 AE
const denomination = AE_AMOUNT_FORMATS.AE
const receiverKeys = generateKeyPair()
const receiver = await BaseAe()
// send coins
await execute(['account', 'spend', WALLET_NAME, '--password', 'test', '-D', denomination, receiverKeys.publicKey, amount], { withOutReject: true, withNetworkId: true })
const receiverBalance = await receiver.getBalance(receiverKeys.publicKey)
receiverBalance.should.equal(formatAmount(amount, { denomination: AE_AMOUNT_FORMATS.AE }))
})
it('Get account nonce', async () => {
const nonce = await wallet.getAccountNonce(await wallet.address())
JSON.parse(await execute(['account', 'nonce', WALLET_NAME, '--password', 'test', '--json'], { withOutReject: true })).nextNonce.should.equal(nonce)
Expand Down
3 changes: 2 additions & 1 deletion test/cli/chain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { before, describe, it } from 'mocha'
import { configure, BaseAe, execute, parseBlock, ready } from './index'
import { generateKeyPair } from '@aeternity/aepp-sdk/es/utils/crypto'
import MemoryAccount from "@aeternity/aepp-sdk/es/account/memory";

describe('CLI Chain Module', function () {
let wallet
Expand All @@ -35,7 +36,7 @@ describe('CLI Chain Module', function () {
})
it('STATUS', async () => {
const wallet = await BaseAe()
wallet.setKeypair(generateKeyPair())
await wallet.addAccount(MemoryAccount({ keypair: generateKeyPair() }), { select: true })

const { nodeVersion } = await wallet.api.getStatus()
const res = JSON.parse(await execute(['chain', 'status', '--json']))
Expand Down
17 changes: 13 additions & 4 deletions test/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import * as R from 'ramda'
// Workaround until fighting with babel7
require = require('esm')(module/*, options */) // use to handle es6 import/export
const Ae = require('@aeternity/aepp-sdk/es/ae/universal').default
const MemoryAccount = require('@aeternity/aepp-sdk/es/account/memory').default
const Node = require('@aeternity/aepp-sdk/es/node').default
const { generateKeyPair } = require('@aeternity/aepp-sdk/es/utils/crypto')

const cliCommand = './bin/aecli.js'
Expand All @@ -28,18 +30,24 @@ const url = process.env.TEST_URL || 'http://localhost:3013'
const compilerUrl = process.env.COMPILER_URL || 'http://localhost:3080'
const internalUrl = process.env.TEST_INTERNAL_URL || 'http://localhost:3113'
export const networkId = process.env.TEST_NETWORK_ID || 'ae_devnet'
export const forceCompatibility = process.env.FORCE_COMPATIBILITY || false

const TIMEOUT = 18000000

export const KEY_PAIR = generateKeyPair()
export const WALLET_NAME = 'mywallet'


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

const BaseAeWithAccounts = BaseAe

export function configure (mocha) {
mocha.timeout(TIMEOUT)
}
Expand All @@ -64,7 +72,8 @@ export async function ready (mocha) {
}

const client = await BaseAe({ networkId, compilerUrl })
client.setKeypair(KEY_PAIR)
client.removeAccount(await client.address())
await client.addAccount(MemoryAccount({ keypair: KEY_PAIR }), { select: true })
await execute(['account', 'save', WALLET_NAME, '--password', 'test', KEY_PAIR.secretKey, '--overwrite'])
return client
}
Expand Down
3 changes: 2 additions & 1 deletion test/cli/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { describe, it } from 'mocha'

import { configure, BaseAe, execute, parseBlock, ready } from './index'
import { decodeBase64Check, generateKeyPair } from '@aeternity/aepp-sdk/es/utils/crypto'
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory'
import fs from 'fs'
import { ABI_VERSIONS, VM_TYPE, VM_VERSIONS } from '../../bin/utils/constant'

Expand Down Expand Up @@ -68,7 +69,7 @@ describe('CLI Transaction Module', function () {
await GENESIS.spend('100000000000000000000000000', TX_KEYS.publicKey)
await execute(['account', 'save', WALLET_NAME, '--password', 'test', TX_KEYS.secretKey, '--overwrite'])
wallet = await BaseAe()
wallet.setKeypair(TX_KEYS)
await wallet.addAccount(MemoryAccount({ keypair: TX_KEYS }))
fs.writeFileSync('contractTest', testContract)
nonce = await wallet.getAccountNonce()
})
Expand Down

0 comments on commit 60b7910

Please sign in to comment.