Skip to content

Commit

Permalink
Merge e1dd72c into 185dd6b
Browse files Browse the repository at this point in the history
  • Loading branch information
e00dan committed Oct 12, 2018
2 parents 185dd6b + e1dd72c commit f6309d2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 43 deletions.
4 changes: 2 additions & 2 deletions test/e2e/TestScheduleTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const SCHEDULED_TX_PARAMS = {
callValue: new BigNumber(Math.pow(10, 18))
};

export const scheduleTestTx = async () => {
export const scheduleTestTx = async (blocksInFuture = 270) => {
const eac = EAC(web3);

const scheduler = await eac.scheduler();
Expand Down Expand Up @@ -42,7 +42,7 @@ export const scheduleTestTx = async () => {
'', // callData
callValue,
30, // windowSize
(await util.getBlockNumber()) + 270, // windowStart
(await util.getBlockNumber()) + blocksInFuture, // windowStart
gasPrice, // gasPrice
fee,
bounty,
Expand Down
20 changes: 2 additions & 18 deletions test/e2e/TestTimeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('TimeNode', () => {
let myAccount: string;
let eac: any;
let web3: any;
let waitUntilBlock: any;
let withSnapshotRevert: any;
let timeNode: TimeNode;

Expand All @@ -23,7 +22,6 @@ describe('TimeNode', () => {
web3 = config.web3;

const helpers = getHelperMethods(web3);
waitUntilBlock = helpers.waitUntilBlock;
withSnapshotRevert = helpers.withSnapshotRevert;

timeNode = new TimeNode(config);
Expand All @@ -46,31 +44,17 @@ describe('TimeNode', () => {
const scheduledTransactionsMap = {};

for (let i = 0; i < TRANSACTIONS_TO_SCHEDULE; i++) {
const transactionAddress: string = await scheduleTestTx();
const transactionAddress: string = await scheduleTestTx(270 + 10 * i);

scheduledTransactionsMap[transactionAddress] = {
executionLogged: false
};
}

const firstScheduledTransactionAddress = Object.keys(scheduledTransactionsMap)[0];
const firstScheduledTransaction = await eac.transactionRequest(
firstScheduledTransactionAddress
);

await firstScheduledTransaction.fillData();

const firstExecutionBlock =
firstScheduledTransaction.windowStart.toNumber() +
firstScheduledTransaction.freezePeriod.toNumber() +
100;

await waitUntilBlock(0, firstExecutionBlock);
await timeNode.startScanning();

console.log('SCHEDULED TX ADDRESSES TO EXECUTE', scheduledTransactionsMap);

await timeNode.startScanning();

timeNode.config.logger.info = (msg: any, txRequest: string) => {
if (msg.includes && msg.includes('EXECUTED') && scheduledTransactionsMap[txRequest]) {
scheduledTransactionsMap[txRequest].executionLogged = true;
Expand Down
24 changes: 1 addition & 23 deletions test/helpers/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,6 @@ export const getHelperMethods = (web3: any) => {
});
}

function waitUntilBlock(seconds: any, targetBlock: any) {
return new Promise((resolve, reject) => {
const asyncIterator = function _asyncIterator() {
return web3.eth.getBlock('latest', (err: any, ref: any) => {
if (err) {
reject(err);
}

const num = ref.number;

if (num >= targetBlock - 1) {
return sendRpc('evm_increaseTime', [seconds])
.then(() => sendRpc('evm_mine'))
.then(resolve);
}
return sendRpc('evm_mine').then(asyncIterator);
});
};
asyncIterator();
});
}

function takeSnapshot(): Promise<number> {
return sendRpc('evm_snapshot').then(res => res.result);
}
Expand All @@ -58,5 +36,5 @@ export const getHelperMethods = (web3: any) => {
return revertSnapshot(snapshot);
}

return { waitUntilBlock, withSnapshotRevert };
return { withSnapshotRevert };
};
4 changes: 4 additions & 0 deletions test/unit/UnitTestTimeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ describe('TimeNode Unit Tests', () => {
});

describe('getClaimedNotExecutedTransactions()', () => {
beforeEach(() => {
timenode.config.statsDb.clearAll();
});

it('returns 0 when no transactions', () => {
const txs = timenode.getClaimedNotExecutedTransactions()[myAccount];
assert.equal(txs.length, 0);
Expand Down

0 comments on commit f6309d2

Please sign in to comment.