Skip to content

Commit

Permalink
Merge pull request #51 from Alien-Worlds/DEMZNE-1084-test-fixes
Browse files Browse the repository at this point in the history
Demzne 1084 test fixes
  • Loading branch information
angelol authored Oct 4, 2022
2 parents 3c36a11 + 196706b commit 1e91070
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 56 deletions.
16 changes: 8 additions & 8 deletions contracts/TestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
generateTypes,
debugPromise,
UpdateAuth,
Asset,
} from 'lamington';

// Dac contracts
Expand All @@ -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';
Expand Down Expand Up @@ -203,7 +205,7 @@ export class SharedTestObjects {

async getRegMembers(
dacId: string,
initialDacAsset: string,
initialDacAsset: string | Asset,
count: number = this.NUMBER_OF_REG_MEMBERS
): Promise<Account[]> {
const newMembers = await AccountManager.createAccounts(count);
Expand Down Expand Up @@ -888,18 +890,16 @@ export class SharedTestObjects {
}

async configTokenContract() {
this.eosio_token_contract =
await ContractDeployer.deployWithName<EosioToken>(
'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,
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/daccustodian/daccustodian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
assertRowsEqual,
TableRowsResult,
assertBalanceEqual,
Asset,
} from 'lamington';

import {
Expand Down Expand Up @@ -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;
Expand Down
62 changes: 18 additions & 44 deletions contracts/stakevote/stakevote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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 },
Expand All @@ -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');
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down

0 comments on commit 1e91070

Please sign in to comment.