Skip to content

Commit

Permalink
Feat: Add changelog and e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
lmuntaner committed Jul 6, 2022
1 parent bce0d41 commit cfdc19e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/generated/changelog.html
Expand Up @@ -10,6 +10,20 @@
<h1>Agent-JS Changelog</h1>

<section>
<h2>Version x.x.x</h2>
<ul>
<li>
Adds a public method "createReadStateRequest" that creates the request for "readState".
</li>
<li>
Add an extra parameter to "readState" to pass a created request. If this parameter is
passed, the method does the request directly without creating a new one.
</li>
<li>
Use the "createReadStateRequest" and the extra parameter when polling for the response to
avoid signing requests during polling.
</li>
</ul>
<h2>Version 0.12.0</h2>
<ul>
<li>
Expand Down
36 changes: 36 additions & 0 deletions e2e/node/basic/basic.test.ts
Expand Up @@ -36,6 +36,42 @@ test('read_state', async () => {
expect(Math.abs(time - now) < 5).toBe(true);
});

test('read_state with passed request', async () => {
const resolvedAgent = await agent;
const now = Date.now() / 1000;
const path = [new TextEncoder().encode('time')];
const canisterId = Principal.fromHex('00000000000000000001');
const request = await resolvedAgent.createReadStateRequest({ paths: [path] });
const response = await resolvedAgent.readState(
canisterId,
{
paths: [path],
},
undefined,
request,
);
if (resolvedAgent.rootKey == null) throw new Error(`The agent doesn't have a root key yet`);
const cert = await Certificate.create({
certificate: response.certificate,
rootKey: resolvedAgent.rootKey,
canisterId: canisterId,
});
expect(cert.lookup([new TextEncoder().encode('Time')])).toBe(undefined);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const rawTime = cert.lookup(path)!;
const decoded = IDL.decode(
[IDL.Nat],
new Uint8Array([
...new TextEncoder().encode('DIDL\x00\x01\x7d'),
...(new Uint8Array(rawTime) || []),
]),
)[0];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const time = Number(decoded as any) / 1e9;
// The diff between decoded time and local time is within 5s
expect(Math.abs(time - now) < 5).toBe(true);
});

test('createCanister', async () => {
// Make sure this doesn't fail.
await getManagementCanister({
Expand Down

0 comments on commit cfdc19e

Please sign in to comment.