diff --git a/contracts/TestHelpers.ts b/contracts/TestHelpers.ts index 4a7cdb00..0ab74202 100644 --- a/contracts/TestHelpers.ts +++ b/contracts/TestHelpers.ts @@ -7,6 +7,7 @@ import { generateTypes, debugPromise, UpdateAuth, + Asset, } from 'lamington'; // Dac contracts @@ -20,6 +21,7 @@ import { Referendum } from './referendum/referendum'; import { Stakevote } from './stakevote/stakevote'; import { EosioToken } from '../../external_contracts/eosio.token/eosio.token'; import { Atomicassets } from './atomicassets/atomicassets'; //'../external_contracts/atomicassets/atomicassets'; +import * as chai from 'chai'; import * as fs from 'fs'; import * as path from 'path'; @@ -203,7 +205,7 @@ export class SharedTestObjects { async getRegMembers( dacId: string, - initialDacAsset: string, + initialDacAsset: string | Asset, count: number = this.NUMBER_OF_REG_MEMBERS ): Promise { const newMembers = await AccountManager.createAccounts(count); @@ -888,18 +890,16 @@ export class SharedTestObjects { } async configTokenContract() { - this.eosio_token_contract = - await ContractDeployer.deployWithName( - 'eosio.token', - 'alien.worlds' - ); + this.eosio_token_contract = await ContractDeployer.deployWithName< + EosioToken + >('eosio.token', 'alien.worlds'); - this.tokenIssuer = await AccountManager.createAccount('tokenissuer'); + this.tokenIssuer = await AccountManager.createAccount('federation'); try { await this.eosio_token_contract.create( this.tokenIssuer.name, - '1000000000.0000 TLM', + '10000000000.0000 TLM', { from: this.eosio_token_contract.account, } diff --git a/contracts/daccustodian/daccustodian.test.ts b/contracts/daccustodian/daccustodian.test.ts index 35c7eb62..5fc739f2 100644 --- a/contracts/daccustodian/daccustodian.test.ts +++ b/contracts/daccustodian/daccustodian.test.ts @@ -11,6 +11,7 @@ import { assertRowsEqual, TableRowsResult, assertBalanceEqual, + Asset, } from 'lamington'; import { @@ -3414,10 +3415,9 @@ async function get_balance( scope: account.name, }); for (const row of res.rows) { - const bal = row.balance; - const [amount, symbol] = bal.split(' '); - if (symbol == search_symbol) { - return parseFloat(amount); + const bal = new Asset(row.balance); + if (bal.symbol == search_symbol) { + return bal.amount; } } return 0.0; diff --git a/contracts/stakevote/stakevote.test.ts b/contracts/stakevote/stakevote.test.ts index 71dace5c..1247e62b 100644 --- a/contracts/stakevote/stakevote.test.ts +++ b/contracts/stakevote/stakevote.test.ts @@ -6,7 +6,10 @@ import { assertRowCount, assertRowsEqual, UpdateAuth, + Asset, } from 'lamington'; +import { SharedTestObjects, NUMBER_OF_CANDIDATES } from '../TestHelpers'; +import * as chai from 'chai'; enum state_keys { total_weight_of_votes = 1, @@ -24,28 +27,8 @@ const years = 12 * months; const STAKE_DURATION_FACTOR = 10; -import { SharedTestObjects, NUMBER_OF_CANDIDATES } from '../TestHelpers'; -import * as chai from 'chai'; let shared: SharedTestObjects; -/* Asset class to be moved to lamginton later */ -class Asset { - amount: number; - symbol: string; - precision: number; - constructor(amount, symbol, precision = 4) { - this.amount = amount; - this.symbol = symbol; - this.precision = precision; - } - toString() { - return `${this.amount.toFixed(this.precision)} ${this.symbol}`; - } - amount_raw() { - return this.amount * 10 ** this.precision; - } -} - describe('Stakevote', () => { before(async () => { shared = await SharedTestObjects.getInstance(); @@ -79,8 +62,7 @@ describe('Stakevote', () => { `${precision},${symbol}`, { from: shared.auth_account } ); - - regMembers = await shared.getRegMembers(dacId, stake_amount.toString()); + regMembers = await shared.getRegMembers(dacId, stake_amount); await shared.stakevote_contract.updateconfig( { time_multiplier: 10 ** 8 }, @@ -105,18 +87,14 @@ describe('Stakevote', () => { await shared.dac_token_contract.transfer( shared.dac_token_contract.account.name, staker.name, - stake_amount.toString(), + stake_amount, '', { from: shared.dac_token_contract.account } ); - await shared.dac_token_contract.stake( - staker.name, - stake_amount.toString(), - { - from: staker, - } - ); + await shared.dac_token_contract.stake(staker.name, stake_amount, { + from: staker, + }); }); it('before voting, total_weight_of_votes should be zero', async () => { const x = await get_from_dacglobals(dacId, 'total_weight_of_votes'); @@ -156,13 +134,9 @@ describe('Stakevote', () => { ); }); it('should work', async () => { - await shared.dac_token_contract.unstake( - staker.name, - stake_amount.toString(), - { - from: staker, - } - ); + await shared.dac_token_contract.unstake(staker.name, stake_amount, { + from: staker, + }); }); it('should remove weights table entries', async () => { await assertRowCount( @@ -258,7 +232,7 @@ describe('Stakevote', () => { for (const member of regMembers) { await shared.dac_token_contract.stake( member.name, - stake_amount.toString(), + stake_amount, { from: member, } @@ -292,13 +266,14 @@ describe('Stakevote', () => { ); }); it('Should have highest ranked votes in custodians', async () => { - let rowsResult = - await shared.daccustodian_contract.custodiansTable({ + let rowsResult = await shared.daccustodian_contract.custodiansTable( + { scope: dacId, limit: 14, indexPosition: 3, keyType: 'i64', - }); + } + ); let rs = rowsResult.rows; rs.sort((a, b) => { return a.total_votes < b.total_votes @@ -350,7 +325,7 @@ describe('Stakevote', () => { dacId, { from: voter } ); - await stake(voter, stake_amount.toString()); + await stake(voter, stake_amount); }); context('for 1 candidate', async () => { let total_weight_of_votes_before: number; @@ -375,8 +350,7 @@ describe('Stakevote', () => { dacId, 'total_votes_on_candidates' ); - total_votes_on_candidates_beginning = - total_votes_on_candidates_before; + total_votes_on_candidates_beginning = total_votes_on_candidates_before; }); it('should work', async () => { const cust1 = candidates[0];