Skip to content

Commit

Permalink
Fixing test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Pauan committed Aug 4, 2024
1 parent ac7f685 commit e7e9374
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ version: 2.1


orbs:
node: circleci/node@5.1.0
node: circleci/node@5.2.0


executors:
rust-node:
docker:
- image: cimg/rust:1.73-node
- image: cimg/rust:1.80-node


commands:
Expand Down
1 change: 1 addition & 0 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@rollup/plugin-replace": "^5.0.5",
"@types/chai": "^4.3.16",
"@types/mime": "^3.0.1",
"@types/mocha": "^10.0.7",
"@types/sinon": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
Expand Down
7 changes: 3 additions & 4 deletions sdk/tests/key-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('KeyProvider', () => {
} catch (e) {
expect(e).instanceof(Error);
}
}, 60000);
});

it('Should use cache when set and not use it when not', async () => {
// Ensure the cache properly downloads and stores keys
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('KeyProvider', () => {
expect(keyProvider.cache.size).equal(0);
expect(redownloadedProvingKey).instanceof(ProvingKey);
expect(redownloadedVerifyingKey).instanceof(VerifyingKey);
}, 200000);
});

it.skip("Should not fetch offline keys that haven't already been stored", async () => {
// Download the credits.aleo function keys
Expand Down Expand Up @@ -139,7 +139,6 @@ describe('KeyProvider', () => {
expect(transferPublicToPrivateVerifierLocal.isTransferPublicToPrivateVerifier()).equal(true);
expect(unbondPublicProverLocal.isUnbondPublicProver()).equal(true);
expect(unbondPublicVerifierLocal.isUnbondPublicVerifier()).equal(true);

}, 380000);
});
});
});
11 changes: 5 additions & 6 deletions sdk/tests/network-client.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ describe('NodeConnection', () => {
if (!(records instanceof Error)) {
expect(records.length).above(0);
}
}, 60000);
});

it('should find records when a private key is pre-configured', async () => {
const records = await remoteApiClientWithPrivateKey.findUnspentRecords(0, undefined, undefined, undefined, 100, []);
expect(Array.isArray(records)).equal(true);
if (!(records instanceof Error)) {
expect(records.length).above(0);
}
}, 60000);
});

it('should find records even when block height specified is higher than current block height', async () => {
const records = await localApiClient.findUnspentRecords(0, 50000000000000, beaconPrivateKeyString, undefined, 100, []);
expect(Array.isArray(records)).equal(true);
if (!(records instanceof Error)) {
expect(records.length).above(0);
}
}, 60000);
});

it('should find records with specified amounts', async () => {
let records = await localApiClient.findUnspentRecords(0, 3, beaconPrivateKeyString, [100, 200], undefined, []);
Expand All @@ -51,7 +51,7 @@ describe('NodeConnection', () => {
if (!(records instanceof Error)) {
expect(records.length).above(0);
}
}, 60000);
});

it('should not find records with existing nonces', async () => {
const nonces: string[] = [];
Expand All @@ -75,7 +75,6 @@ describe('NodeConnection', () => {
});
}
}

}, 60000);
});
});
});
36 changes: 18 additions & 18 deletions sdk/tests/network-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ describe('NodeConnection', () => {
const account = new Account();
connection.setAccount(account);
expect(connection.getAccount()).equal(account);
}, 60000);
});
});

describe('getBlock', () => {
it.skip('should return a Block object', async () => {
const block = await connection.getBlock(1);
expect((block as Block).block_hash).equal("ab17jdwevmgu20kcqazp2wjyy2u2k75rac2mtvuf6w6kjn8egv0uvrqe7mra6");
}, 60000);
});

it('should throw an error if the request fails', async () => {
await expectThrows(
() => connection.getBlock(99999999),
"Error fetching block.",
);
}, 60000);
});
});

describe('getBlockRange', () => {
Expand All @@ -67,18 +67,18 @@ describe('NodeConnection', () => {
expect(((blockRange as Block[])[0] as Block).block_hash).equal("ab17jdwevmgu20kcqazp2wjyy2u2k75rac2mtvuf6w6kjn8egv0uvrqe7mra6");
expect(((blockRange as Block[])[1] as Block).block_hash).equal("ab1q60nvh5ha8ld43x0jph9futqwkdm4j3cvw5a2unj5d23ml090c9qkcvr3g");

}, 60000);
});

it('should throw an error if the request fails', async () => {
expect(await connection.getBlockRange(999999999, 1000000000)).deep.equal([]);
}, 60000);
});
});

describe('getProgram', () => {
it('should return a string', async () => {
const program = await connection.getProgram('credits.aleo');
expect(typeof program).equal('string');
}, 60000);
});

it('should throw an error if the request fails', async () => {
const program_id = "a" + (Math.random()).toString(32).substring(2) + ".aleo";
Expand All @@ -87,14 +87,14 @@ describe('NodeConnection', () => {
() => connection.getProgram(program_id),
"Error fetching program",
);
}, 60000);
});
});

describe('getLatestBlock', () => {
it('should return a Block object', async () => {
const latestBlock = await connection.getLatestBlock();
expect(typeof (latestBlock as Block).block_hash).equal('string');
}, 60000);
});

it('should set the X-Aleo-SDK-Version header', async () => {
expect(windowFetchSpy.args).deep.equal([]);
Expand All @@ -113,28 +113,28 @@ describe('NodeConnection', () => {
}
],
]);
}, 60000);
});
});

describe('getLatestCommittee', () => {
it('should return a string', async () => {
const latestCommittee = await connection.getLatestCommittee();
expect(typeof latestCommittee).equal('object');
}, 60000);
});
});

describe('getLatestHeight', () => {
it('should return a number', async () => {
const latestHeight = await connection.getLatestHeight();
expect(typeof latestHeight).equal('number');
}, 60000);
});
});

describe('getStateRoot', () => {
it('should return a string', async () => {
const stateRoot = await connection.getStateRoot();
expect(typeof stateRoot).equal('string');
}, 60000);
});
});

describe('getTransactions', () => {
Expand All @@ -143,15 +143,15 @@ describe('NodeConnection', () => {
() => connection.getTransactions(999999999),
"Error fetching transactions.",
);
}, 60000);
});
});

describe('getProgramImports', () => {
it('should return the correct program import names', async () => {
const creditImports = await connection.getProgramImportNames("credits.aleo");
const expectedCreditImports: string[] = [];
expect(creditImports).deep.equal(expectedCreditImports);
}, 60000);
});

it.skip('should return all nested imports', async () => {
const imports = await connection.getProgramImports("imported_add_mul.aleo");
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('NodeConnection', () => {
' output r2 as u32.private;\n'
};
expect(imports).equal(expectedImports);
}, 60000);
});
});

describe('findUnspentRecords', () => {
Expand All @@ -204,15 +204,15 @@ describe('NodeConnection', () => {
() => connection.findUnspentRecords(0, 5, undefined, undefined, undefined, []),
"Private key must be specified in an argument to findOwnedRecords or set in the AleoNetworkClient",
);
}, 60000);
});

it.skip('should search a range correctly and not find records where none exist', async () => {
const records = await connection.findUnspentRecords(0, 204, beaconPrivateKeyString, undefined, undefined, []);
expect(Array.isArray(records)).equal(true);
if (!(records instanceof Error)) {
expect(records.length).equal(0);
}
}, 90000);
});
});

describe('Mappings', () => {
Expand All @@ -221,6 +221,6 @@ describe('NodeConnection', () => {
if (!(mappings instanceof Error)) {
expect(mappings).deep.equal(["committee", "delegated", "metadata", "bonded", "unbonding", "account", "withdraw"]);
}
}, 60000);
});
});
});
6 changes: 3 additions & 3 deletions sdk/tests/program-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Program Manager', () => {
const execution_result = <ExecutionResponse>await programManager.run(helloProgram, "hello", ["5u32", "5u32"], true, undefined, undefined, undefined, undefined, undefined, undefined)
expect(execution_result.getOutputs()[0]).equal("10u32");
programManager.verifyExecution(execution_result);
}, 1020000);
});
});

describe('Offline query', () => {
Expand All @@ -32,12 +32,12 @@ describe('Program Manager', () => {
const execution_result = <ExecutionResponse>await programManager.run(credits, "transfer_private", [statePathRecord, beaconAddressString, "5u64"], true, undefined, undefined, undefined, undefined, undefined, offlineQuery);
const verified = programManager.verifyExecution(execution_result);
expect(verified).equal(true);
}, 1020000);
});
});

describe('Staking - Bond Public', () => {
it.skip('Should execute bondPublic', async () => {
// TODO
}, 420000);
});
});
});
2 changes: 1 addition & 1 deletion sdk/tests/record-provider.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ describe('RecordProvider', () => {
} catch (e) {
throw e;
}
}, 60000);
});
});
});
3 changes: 2 additions & 1 deletion sdk/tests/record-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe.skip('RecordProvider', () => {
let account: Account;
let networkClient: AleoNetworkClient;
let recordProvider: NetworkRecordProvider;

beforeEach(() => {
account = new Account({privateKey: beaconPrivateKeyString});
networkClient = new AleoNetworkClient("http://vm.aleo.org/api");
Expand All @@ -23,6 +24,6 @@ describe.skip('RecordProvider', () => {
log(e)
throw e;
}
}, 60000);
});
});
});
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2480,6 +2480,11 @@
dependencies:
"@types/node" "*"

"@types/mocha@^10.0.7":
version "10.0.7"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.7.tgz#4c620090f28ca7f905a94b706f74dc5b57b44f2f"
integrity sha512-GN8yJ1mNTcFcah/wKEFIJckJx9iJLoMSzWcfRRuxz/Jk+U6KQNnml+etbtxFK8lPjzOw3zp4Ha/kjSst9fsHYw==

"@types/node@*":
version "22.1.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.1.0.tgz#6d6adc648b5e03f0e83c78dc788c2b037d0ad94b"
Expand Down

0 comments on commit e7e9374

Please sign in to comment.