Skip to content

Commit 8050845

Browse files
committed
Fixing some tests
Split handleSignatureRequired Another fund and send should not check inBlock Additional fixes Additional small fixes More fixes Fix final e2e test maybe More test fixes Grant Delegation Test fixes Keys should already be registered as an MSA and cleanup test file Fixing and splitting grantDelegations More fixes Removing more race conditions Add some invalid error messages for debugging help Split up handles test
1 parent c1ef277 commit 8050845

34 files changed

+1624
-1329
lines changed

e2e/.mocharc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"exit": true,
3+
"fullTrace": true,
34
"extension": ["ts"],
45
"parallel": true,
56
"require": ["scaffolding/globalHooks.ts", "scaffolding/rootHooks.ts", "scaffolding/extrinsicHelpers.ts"],

e2e/.relay-chain-all.mocharc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"exit": true,
3+
"fullTrace": true,
34
"extension": ["ts"],
45
"parallel": true,
56
"require": ["scaffolding/globalHooks.ts", "scaffolding/rootHooks.ts", "scaffolding/extrinsicHelpers.ts"],

e2e/.relay-chain.mocharc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"exit": true,
3+
"fullTrace": true,
34
"extension": ["ts"],
45
"require": ["scaffolding/rootHooks.ts", "scaffolding/extrinsicHelpers.ts"],
56
"import": "tsx/esm",

e2e/capacity/capacityFail.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,13 @@ describe('Capacity Transaction Failures', function () {
160160
// from the transaction pool.
161161
it('fails to pay for a transaction with empty capacity', async function () {
162162
const noCapacityKeys = createKeys('noCapacityKeys');
163-
const noCapacityProvider = await createMsaAndProvider(fundingSource, noCapacityKeys, 'NoCapProvider');
163+
const noCapacityProvider = await createMsaAndProvider(
164+
fundingSource,
165+
noCapacityKeys,
166+
'NoCapProvider',
167+
undefined,
168+
false
169+
);
164170

165171
const delegatorKeys = createKeys('delegatorKeys');
166172

e2e/capacity/change_staking_target.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ const fundingSource = getFundingSource(import.meta.url);
1515

1616
describe('Capacity: change_staking_target', function () {
1717
const tokenMinStake: bigint = 1n * CENTS;
18-
const capacityMin: bigint = tokenMinStake / 50n;
1918

2019
it('successfully stake tokens to a provider', async function () {
2120
const providerBalance = 2n * DOLLARS;
2221
const stakeKeys = createKeys('staker');
23-
const oldProvider = await createMsaAndProvider(fundingSource, stakeKeys, 'Provider1', providerBalance);
24-
const [_bar, newProvider] = await createProviderKeysAndId(fundingSource, providerBalance);
2522

23+
// Setup
24+
const [oldProvider, [_bar, newProvider]] = await Promise.all([
25+
createMsaAndProvider(fundingSource, stakeKeys, 'Provider1', providerBalance),
26+
createProviderKeysAndId(fundingSource, providerBalance),
27+
]);
28+
29+
// Stake
2630
await assert.doesNotReject(stakeToProvider(fundingSource, stakeKeys, oldProvider, tokenMinStake * 3n));
2731

32+
// Change Stake
2833
const call = ExtrinsicHelper.changeStakingTarget(stakeKeys, oldProvider, newProvider, tokenMinStake);
2934
const events = await call.signAndSend();
3035
assert.notEqual(events, undefined);

e2e/capacity/staking.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ describe('Capacity Staking Tests', function () {
326326

327327
const vestedTransferTx = ExtrinsicHelper.timeReleaseTransfer(fundingSource, vesterKeys, schedule);
328328

329-
await assert.doesNotReject(vestedTransferTx.signAndSend());
329+
await assert.doesNotReject(vestedTransferTx.signAndSend(undefined, undefined, false));
330330
await assertFrozen(vesterKeys, 100n * DOLLARS);
331331

332332
await assert.doesNotReject(ExtrinsicHelper.stake(vesterKeys, providerId, 80n * DOLLARS).signAndSend());

e2e/eslint.config.mjs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,13 @@
33
import eslint from '@eslint/js';
44
import globals from 'globals';
55
import tseslint from 'typescript-eslint';
6-
import mocha from 'eslint-plugin-mocha';
7-
8-
// Needed for eslint 9
9-
const mochaConfig = [
10-
{
11-
name: 'mocha/recommended',
12-
languageOptions: {
13-
globals: globals.mocha,
14-
},
15-
plugins: {
16-
mocha,
17-
},
18-
rules: mocha.configs.flat.recommended.rules,
19-
},
20-
];
6+
import mochaPlugin from 'eslint-plugin-mocha';
217

228
export default tseslint.config(
239
eslint.configs.recommended,
10+
mochaPlugin.configs.recommended,
2411
...tseslint.configs.strict,
2512
...tseslint.configs.stylistic,
26-
...mochaConfig,
2713
{
2814
ignores: ['dist/'],
2915
},

e2e/handles/handles.test.ts

Lines changed: 46 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Handles test suite
1+
// Handles Basic test suite
22
import '@frequency-chain/api-augment';
33
import assert from 'assert';
4-
import { createMsa, DOLLARS, getTestHandle } from '../scaffolding/helpers';
4+
import { CENTS, createMsa, DOLLARS, getTestHandle } from '../scaffolding/helpers';
55
import { KeyringPair } from '@polkadot/keyring/types';
66
import { MessageSourceId } from '@frequency-chain/api-augment/interfaces';
77
import { ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
@@ -13,199 +13,54 @@ import { getFundingSource } from '../scaffolding/funding';
1313
const fundingSource = getFundingSource(import.meta.url);
1414
const expirationOffset = hasRelayChain() ? 4 : 100;
1515

16-
describe('🤝 Handles', function () {
17-
describe('Claim and Retire', function () {
18-
let msa_id: MessageSourceId;
19-
let msaOwnerKeys: KeyringPair;
16+
describe('Handles: Claim and Retire', function () {
17+
let msaId: MessageSourceId;
18+
let msaOwnerKeys: KeyringPair;
2019

21-
before(async function () {
22-
// Create a MSA for the delegator
23-
[msa_id, msaOwnerKeys] = await createMsa(fundingSource);
24-
assert.notEqual(msaOwnerKeys, undefined, 'setup should populate delegator_key');
25-
assert.notEqual(msa_id, undefined, 'setup should populate msa_id');
26-
});
27-
28-
it('should be able to claim a handle', async function () {
29-
const handle = getTestHandle();
30-
const currentBlock = await getBlockNumber();
31-
const handle_vec = new Bytes(ExtrinsicHelper.api.registry, handle);
32-
const payload = {
33-
baseHandle: handle_vec,
34-
expiration: currentBlock + expirationOffset,
35-
};
36-
const claimHandlePayload = ExtrinsicHelper.api.registry.createType(
37-
'CommonPrimitivesHandlesClaimHandlePayload',
38-
payload
39-
);
40-
const claimHandle = ExtrinsicHelper.claimHandle(msaOwnerKeys, claimHandlePayload);
41-
const { target: event } = await claimHandle.fundAndSend(fundingSource);
42-
assert.notEqual(event, undefined, 'claimHandle should return an event');
43-
assert.notEqual(event!.data.handle.toString(), '', 'claimHandle should emit a handle');
44-
});
45-
46-
it('should be able to retire a handle', async function () {
47-
const handle_response = await ExtrinsicHelper.getHandleForMSA(msa_id);
48-
if (!handle_response.isSome) {
49-
throw new Error('handle_response should be Some');
50-
}
51-
const full_handle_state = handle_response.unwrap();
52-
const suffix_from_state = full_handle_state.suffix;
53-
const suffix = suffix_from_state.toNumber();
54-
assert.notEqual(suffix, 0, 'suffix should not be 0');
55-
assert.notEqual(full_handle_state.canonical_base, undefined, 'canonical_base should not be undefined');
56-
assert.notEqual(full_handle_state.base_handle, undefined, 'base_handle should not be undefined');
57-
const currentBlock = await getBlockNumber();
58-
await ExtrinsicHelper.runToBlock(currentBlock + expirationOffset + 1); // Must be at least 1 > original expiration
59-
60-
const retireHandle = ExtrinsicHelper.retireHandle(msaOwnerKeys);
61-
const { target: event } = await retireHandle.signAndSend();
62-
assert.notEqual(event, undefined, 'retireHandle should return an event');
63-
const handle = event!.data.handle.toString();
64-
assert.notEqual(handle, '', 'retireHandle should return the correct handle');
65-
});
66-
});
67-
68-
describe('Claim and Retire Alt', function () {
69-
let msa_id: MessageSourceId;
70-
let msaOwnerKeys: KeyringPair;
71-
72-
before(async function () {
73-
// Create a MSA for the delegator
74-
[msa_id, msaOwnerKeys] = await createMsa(fundingSource);
75-
assert.notEqual(msaOwnerKeys, undefined, 'setup should populate delegator_key');
76-
assert.notEqual(msa_id, undefined, 'setup should populate msa_id');
77-
});
78-
79-
describe('Claim Handle with possible presumptive suffix/RPC test', function () {
80-
it('should be able to claim a handle and check suffix (=suffix_assumed if available on chain)', async function () {
81-
const handle = getTestHandle();
82-
const handle_bytes = new Bytes(ExtrinsicHelper.api.registry, handle);
83-
/// Get presumptive suffix from chain (rpc)
84-
const suffixes_response = await ExtrinsicHelper.getNextSuffixesForHandle(handle, 10);
85-
const resp_base_handle = suffixes_response.base_handle.toString();
86-
assert.equal(resp_base_handle, handle, 'resp_base_handle should be equal to handle');
87-
const suffix_assumed = suffixes_response.suffixes[0];
88-
assert.notEqual(suffix_assumed, 0, 'suffix_assumed should not be 0');
89-
90-
const currentBlock = await getBlockNumber();
91-
/// Claim handle (extrinsic)
92-
const payload_ext = {
93-
baseHandle: handle_bytes,
94-
expiration: currentBlock + expirationOffset,
95-
};
96-
const claimHandlePayload = ExtrinsicHelper.api.registry.createType(
97-
'CommonPrimitivesHandlesClaimHandlePayload',
98-
payload_ext
99-
);
100-
const claimHandle = ExtrinsicHelper.claimHandle(msaOwnerKeys, claimHandlePayload);
101-
const { target: event } = await claimHandle.fundAndSend(fundingSource);
102-
assert.notEqual(event, undefined, 'claimHandle should return an event');
103-
const displayHandle = event!.data.handle.toUtf8();
104-
assert.notEqual(displayHandle, '', 'claimHandle should emit a handle');
105-
106-
// get handle using msa (rpc)
107-
const handle_response = await ExtrinsicHelper.getHandleForMSA(msa_id);
108-
if (!handle_response.isSome) {
109-
throw new Error('handle_response should be Some');
110-
}
111-
const full_handle_state = handle_response.unwrap();
112-
const suffix_from_state = full_handle_state.suffix;
113-
const suffix = suffix_from_state.toNumber();
114-
assert.notEqual(suffix, 0, 'suffix should not be 0');
115-
assert.equal(suffix, suffix_assumed, 'suffix should be equal to suffix_assumed');
116-
117-
/// Get MSA from full display handle (rpc)
118-
const msaOption = await ExtrinsicHelper.getMsaForHandle(displayHandle);
119-
assert(msaOption.isSome, 'msaOption should be Some');
120-
const msaFromHandle = msaOption.unwrap();
121-
assert.equal(msaFromHandle.toString(), msa_id.toString(), 'msaFromHandle should be equal to msa_id');
122-
123-
// Check that the rpc returns the index as > 0
124-
const apiCheck = await ExtrinsicHelper.apiPromise.call.handlesRuntimeApi.checkHandle(handle);
125-
assert(apiCheck.suffixIndex.toNumber() > 0);
126-
});
127-
});
128-
129-
describe('👇 Negative Test: Early retire handle', function () {
130-
it('should not be able to retire a handle before expiration', async function () {
131-
const handle_response = await ExtrinsicHelper.getHandleForMSA(msa_id);
132-
if (!handle_response.isSome) {
133-
throw new Error('handle_response should be Some');
134-
}
135-
136-
const full_handle_state = handle_response.unwrap();
137-
const suffix_from_state = full_handle_state.suffix;
138-
const suffix = suffix_from_state.toNumber();
139-
assert.notEqual(suffix, 0, 'suffix should not be 0');
140-
141-
const currentBlock = await getBlockNumber();
142-
await ExtrinsicHelper.runToBlock(currentBlock + expirationOffset + 1);
143-
try {
144-
const retireHandle = ExtrinsicHelper.retireHandle(msaOwnerKeys);
145-
const { target: event } = await retireHandle.fundAndSend(fundingSource);
146-
assert.equal(event, undefined, 'retireHandle should not return an event');
147-
} catch (e) {
148-
assert.notEqual(e, undefined, 'retireHandle should throw an error');
149-
}
150-
});
151-
});
20+
before(async function () {
21+
// Create a MSA for the delegator
22+
[msaId, msaOwnerKeys] = await createMsa(fundingSource, 50n * CENTS);
23+
assert.notEqual(msaOwnerKeys, undefined, 'setup should populate delegator_key');
24+
assert.notEqual(msaId, undefined, 'setup should populate msaId');
15225
});
15326

154-
describe('Suffixes Integrity Check', function () {
155-
it('should return same suffixes for `abcdefg` from chain as hardcoded', async function () {
156-
const suffixes = await ExtrinsicHelper.getNextSuffixesForHandle('abcdefg', 10);
157-
const suffixes_expected = [23, 65, 16, 53, 25, 75, 29, 26, 10, 87];
158-
const resp_suffixes_number = suffixes.suffixes.map((x) => x.toNumber());
159-
assert.deepEqual(resp_suffixes_number, suffixes_expected, 'suffixes should be equal to suffixes_expected');
160-
});
27+
it('should be able to claim a handle', async function () {
28+
const handle = getTestHandle('A-test');
29+
const currentBlock = await getBlockNumber();
30+
const handle_vec = new Bytes(ExtrinsicHelper.api.registry, handle);
31+
const payload = {
32+
baseHandle: handle_vec,
33+
expiration: currentBlock + expirationOffset,
34+
};
35+
const claimHandlePayload = ExtrinsicHelper.api.registry.createType(
36+
'CommonPrimitivesHandlesClaimHandlePayload',
37+
payload
38+
);
39+
const claimHandle = ExtrinsicHelper.claimHandle(msaOwnerKeys, claimHandlePayload);
40+
const { target: event } = await claimHandle.fundAndSend(fundingSource);
41+
assert.notEqual(event, undefined, 'claimHandle should return an event');
42+
assert.notEqual(event!.data.handle.toString(), '', 'claimHandle should emit a handle');
16143
});
16244

163-
describe('validateHandle basic test', function () {
164-
it('returns true for good handle, and false for bad handle', async function () {
165-
let res = await ExtrinsicHelper.validateHandle('Robert`DROP TABLE STUDENTS;--');
166-
assert.equal(res.toHuman(), false);
167-
res = await ExtrinsicHelper.validateHandle('Little Bobby Tables');
168-
assert.equal(res.toHuman(), true);
169-
res = await ExtrinsicHelper.validateHandle('Bobbay😀😀');
170-
assert.equal(res.toHuman(), false);
171-
});
172-
});
173-
174-
describe('checkHandle basic test', function () {
175-
it('expected outcome for a good handle', async function () {
176-
const res = await ExtrinsicHelper.apiPromise.call.handlesRuntimeApi.checkHandle('Little Bobby Tables');
177-
assert(!res.isEmpty, 'Expected a response');
178-
assert.deepEqual(res.toHuman(), {
179-
baseHandle: 'Little Bobby Tables',
180-
canonicalBase: 'l1tt1eb0bbytab1es',
181-
suffixIndex: '0',
182-
suffixesAvailable: true,
183-
valid: true,
184-
});
185-
});
186-
187-
it('expected outcome for a bad handle', async function () {
188-
const res = await ExtrinsicHelper.apiPromise.call.handlesRuntimeApi.checkHandle('Robert`DROP TABLE STUDENTS;--');
189-
assert(!res.isEmpty, 'Expected a response');
190-
assert.deepEqual(res.toHuman(), {
191-
baseHandle: 'Robert`DROP TABLE STUDENTS;--',
192-
canonicalBase: '',
193-
suffixIndex: '0',
194-
suffixesAvailable: false,
195-
valid: false,
196-
});
197-
});
198-
199-
it('expected outcome for a good handle with complex whitespace', async function () {
200-
const res = await ExtrinsicHelper.apiPromise.call.handlesRuntimeApi.checkHandle('नी हुन्‍न् ।');
201-
assert(!res.isEmpty, 'Expected a response');
202-
assert.deepEqual(res.toHuman(), {
203-
baseHandle: '0xe0a4a8e0a58020e0a4b9e0a581e0a4a8e0a58de2808de0a4a8e0a58d20e0a5a4',
204-
canonicalBase: '0xe0a4a8e0a4b9e0a4a8e0a4a8e0a5a4',
205-
suffixIndex: '0',
206-
suffixesAvailable: true,
207-
valid: true,
208-
});
209-
});
45+
it('should be able to retire a handle', async function () {
46+
const handle_response = await ExtrinsicHelper.getHandleForMSA(msaId);
47+
if (!handle_response.isSome) {
48+
throw new Error('handle_response should be Some');
49+
}
50+
const full_handle_state = handle_response.unwrap();
51+
const suffix_from_state = full_handle_state.suffix;
52+
const suffix = suffix_from_state.toNumber();
53+
assert.notEqual(suffix, 0, 'suffix should not be 0');
54+
assert.notEqual(full_handle_state.canonical_base, undefined, 'canonical_base should not be undefined');
55+
assert.notEqual(full_handle_state.base_handle, undefined, 'base_handle should not be undefined');
56+
const currentBlock = await getBlockNumber();
57+
// Must be at least 6 > original expiration to make sure we get past the finalization
58+
await ExtrinsicHelper.runToBlock(currentBlock + expirationOffset + 6);
59+
60+
const retireHandle = ExtrinsicHelper.retireHandle(msaOwnerKeys);
61+
const { target: event } = await retireHandle.signAndSend();
62+
assert.notEqual(event, undefined, 'retireHandle should return an event');
63+
const handle = event!.data.handle.toString();
64+
assert.notEqual(handle, '', 'retireHandle should return the correct handle');
21065
});
21166
});

0 commit comments

Comments
 (0)