Skip to content

Commit

Permalink
test(channel): fix on testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jun 10, 2024
1 parent ae9c413 commit c986e47
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module.exports = {
require: 'tooling/babel-register.js',
recursive: true,
extension: '.js,.ts',
timeout: process.env.NETWORK ? '500s' : '6s',
timeout: process.env.NETWORK ? '30s' : '6s',
ignore: 'test/environment/**',
}
16 changes: 8 additions & 8 deletions test/integration/aens.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, before } from 'mocha';
import { expect } from 'chai';
import { RestError } from '@azure/core-rest-pipeline';
import { getSdk, isLimitedCoins } from '.';
import { getSdk, isLimitedCoins, timeoutBlock } from '.';
import {
assertNotNull, ensureEqual, randomName, randomString,
} from '../utils';
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('Aens', () => {
assertNotNull(claimRes.tx);
assertNotNull(claimRes.signatures);
expect(claimRes.tx.fee).to.satisfy((fee: bigint) => fee >= 16660000000000n);
expect(claimRes.tx.fee).to.satisfy((fee: bigint) => fee <= 17040000000000n);
expect(claimRes.tx.fee).to.satisfy((fee: bigint) => fee <= 17080000000000n);
expect(claimRes).to.be.eql({
tx: {
fee: claimRes.tx.fee,
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('Aens', () => {
pointers: [],
ttl: claimRes.blockHeight + 180000,
});
});
}).timeout(timeoutBlock);

it('claims a long name without preclaim', async () => {
const nameString = randomName(30);
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Aens', () => {
pointers: [],
ttl: claimRes.blockHeight + 180000,
});
});
}).timeout(timeoutBlock);

it('preclaims name using specific account', async () => {
const onAccount = Object.values(aeSdk.accounts)[1];
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('Aens', () => {
assertNotNull(updateRes.tx);
assertNotNull(updateRes.signatures);
expect(updateRes.tx.fee).to.satisfy((fee: bigint) => fee >= 22140000000000n);
expect(updateRes.tx.fee).to.satisfy((fee: bigint) => fee <= 22180000000000n);
expect(updateRes.tx.fee).to.satisfy((fee: bigint) => fee <= 22240000000000n);
expect(updateRes).to.be.eql({
tx: {
fee: updateRes.tx.fee,
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('Aens', () => {
const txHash = buildTxHash(rawTx);
await expect(aeSdk.poll(txHash))
.to.be.rejectedWith(new RegExp(`v3/transactions/${txHash} error: (Transaction not found|412 status code)`));
});
}).timeout(timeoutBlock);

it('updates extending pointers', async () => {
const anotherContract = buildContractId(address, 12);
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('Aens', () => {
assertNotNull(transferRes.tx);
assertNotNull(transferRes.signatures);
expect(transferRes.tx.fee).to.satisfy((fee: bigint) => fee >= 17300000000000n);
expect(transferRes.tx.fee).to.satisfy((fee: bigint) => fee <= 17340000000000n);
expect(transferRes.tx.fee).to.satisfy((fee: bigint) => fee <= 17400000000000n);
expect(transferRes).to.be.eql({
tx: {
fee: transferRes.tx.fee,
Expand Down Expand Up @@ -359,7 +359,7 @@ describe('Aens', () => {
assertNotNull(revokeRes.tx);
assertNotNull(revokeRes.signatures);
expect(revokeRes.tx.fee).to.satisfy((fee: bigint) => fee >= 16620000000000n);
expect(revokeRes.tx.fee).to.satisfy((fee: bigint) => fee <= 16660000000000n);
expect(revokeRes.tx.fee).to.satisfy((fee: bigint) => fee <= 16700000000000n);
expect(revokeRes).to.be.eql({
tx: {
fee: revokeRes.tx.fee,
Expand Down
6 changes: 3 additions & 3 deletions test/integration/chain.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, before } from 'mocha';
import { expect } from 'chai';
import { stub } from 'sinon';
import { getSdk } from '.';
import { getSdk, timeoutBlock } from '.';
import {
generateKeyPair, AeSdk, Tag, MemoryAccount, Encoded, Node, Contract,
} from '../../src';
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Node Chain', () => {
const target = await aeSdkWithoutAccount.getHeight() + 1;
await aeSdkWithoutAccount.awaitHeight(target).should.eventually.be.at.least(target);
await aeSdkWithoutAccount.getHeight().should.eventually.be.at.least(target);
});
}).timeout(timeoutBlock);

it('Can verify transaction from broadcast error', async () => {
const error = await aeSdk
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('Node Chain', () => {
const res = await aeSdk.spend(1000, aeSdk.address, { confirm: 1 });
assertNotNull(res.blockHeight);
expect(await aeSdk.getHeight() >= res.blockHeight + 1).to.be.equal(true);
});
}).timeout(timeoutBlock);

it('doesn\'t make extra requests', async () => {
let getCount;
Expand Down
9 changes: 6 additions & 3 deletions test/integration/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
import { expect } from 'chai';
import * as sinon from 'sinon';
import BigNumber from 'bignumber.js';
import { getSdk, networkId, channelUrl } from '.';
import {
getSdk, networkId, channelUrl, timeoutBlock,
} from '.';
import {
unpackTx,
buildTxHash,
Expand Down Expand Up @@ -98,6 +100,7 @@ describe('Channel', () => {
initiatorId: 'ak_' as Encoded.AccountAddress,
responderId: 'ak_' as Encoded.AccountAddress,
minimumDepth: 0,
minimumDepthStrategy: 'plain' as const,
};
const initiatorParams = {
role: 'initiator',
Expand Down Expand Up @@ -738,7 +741,7 @@ describe('Channel', () => {
.minus(responderBalanceBeforeClose)
.isEqualTo(balances[responder.address])
.should.be.equal(true);
});
}).timeout(timeoutBlock);

it('can dispute via slash tx', async () => {
initiatorCh.disconnect();
Expand Down Expand Up @@ -809,7 +812,7 @@ describe('Channel', () => {
.plus(settleTxFee)
.isEqualTo(recentBalances[responder.address])
.should.be.equal(true);
});
}).timeout(timeoutBlock);

it('can create a contract and accept', async () => {
initiatorCh.disconnect();
Expand Down
4 changes: 2 additions & 2 deletions test/integration/contract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { before, describe, it } from 'mocha';
import { assertNotNull, InputNumber } from '../utils';
import { getSdk } from '.';
import { getSdk, timeoutBlock } from '.';
import {
ArgumentError, NodeInvocationError, Encoded, DRY_RUN_ACCOUNT,
messageToHash, UnexpectedTsError, AeSdk, Contract, ContractMethodsBase, isAddressValid, Encoding,
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('Contract', () => {
await contract.call({ callStatic: true, top: beforeMicroBlockHash });
await contract.call({ callStatic: true, top: beforeKeyBlockHash });
await contract.call({ callStatic: true, top: beforeKeyBlockHeight });
});
}).timeout(timeoutBlock);

it('call contract/deploy with waitMined: false', async () => {
delete identityContract.$options.address;
Expand Down
8 changes: 4 additions & 4 deletions test/integration/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { before, describe, it } from 'mocha';
import {
assertNotNull, randomName, ChainTtl, InputNumber,
} from '../utils';
import { getSdk } from '.';
import { getSdk, timeoutBlock } from '.';
import {
commitmentHash, decode, encode, Encoded, Encoding,
genSalt, AeSdk, Contract, Oracle, OracleClient, Name,
Expand Down Expand Up @@ -123,7 +123,7 @@ contract DelegateTest =
.signedClaim(owner, name, salt, nameFee, decode(delegationSignature));
assertNotNull(result);
result.returnType.should.be.equal('ok');
});
}).timeout(timeoutBlock);

it('updates', async () => {
const pointee: Pointee = { 'AENSv2.OraclePt': [newOwner] };
Expand Down Expand Up @@ -197,7 +197,7 @@ contract DelegateTest =

const commitmentId = decode(commitmentHash(n, salt));
await contract.signedPreclaim(owner, commitmentId, allNamesDelSig);
await aeSdk.awaitHeight(2 + await aeSdk.getHeight());
await aeSdk.awaitHeight(1 + await aeSdk.getHeight());

await contract.signedClaim(owner, n, salt, nameFee, allNamesDelSig);

Expand All @@ -218,7 +218,7 @@ contract DelegateTest =
.transfer(owner, { onAccount: aeSdk.accounts[newOwner] });

await contract.signedRevoke(owner, n, allNamesDelSig);
});
}).timeout(timeoutBlock);

it('claims without preclaim', async () => {
const n = randomName(30);
Expand Down
2 changes: 2 additions & 0 deletions test/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ afterEach(async function describeTxError() {
const { status } = await response.json();
err.message += ` (node-provided transaction status: ${status})`;
});

export const timeoutBlock = networkId === 'ae_dev' ? 6_000 : 700_000;
7 changes: 3 additions & 4 deletions test/integration/oracle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, before } from 'mocha';
import { expect } from 'chai';
import { RestError } from '@azure/core-rest-pipeline';
import { getSdk, networkId } from '.';
import { getSdk, timeoutBlock } from '.';
import {
AeSdk, decode, encode, Encoding, Encoded, ORACLE_TTL_TYPES, Oracle, OracleClient, LogicError,
} from '../../src';
Expand Down Expand Up @@ -156,19 +156,18 @@ describe('Oracle', () => {
expect(query.tx.query).to.be.equal('{"city": "Berlin"}');
});

const timeout = networkId === 'ae_dev' ? 8000 : 700000;
it('polls for response for query without response', async () => {
const { queryId } = await oracleClient.postQuery('{"city": "Berlin"}', { queryTtlValue: 1 });
await oracleClient.pollForResponse(queryId)
.should.be.rejectedWith(/Giving up at height|error: Query not found/);
}).timeout(timeout);
}).timeout(timeoutBlock);

it('polls for response for query that is already expired without response', async () => {
const { queryId } = await oracleClient.postQuery('{"city": "Berlin"}', { queryTtlValue: 1 });
await aeSdk.awaitHeight(await aeSdk.getHeight() + 2);
await oracleClient.pollForResponse(queryId)
.should.be.rejectedWith(RestError, 'Query not found');
}).timeout(timeout);
}).timeout(timeoutBlock * 2);

it('queries oracle', async () => {
const stopPolling = oracle.pollQueries((query) => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/typed-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('typed data', () => {
+ '\n entrypoint getDomain(): domain =' // kind of EIP-5267
+ '\n { name = Some("Test app"),'
+ '\n version = Some(2),'
+ '\n networkId = Some(Chain.network_id),'
+ '\n networkId = Some("ae_dev"),' // better `Chain.network_id`, but would complicate testing
+ '\n contractAddress = Some(Address.to_contract(Contract.address)) }'
+ '\n'
+ '\n entrypoint getDomainHash() = Crypto.blake2b(getDomain())'
Expand Down

0 comments on commit c986e47

Please sign in to comment.