diff --git a/docs/generated/changelog.html b/docs/generated/changelog.html
index 84aa5df4b..3ef8da558 100644
--- a/docs/generated/changelog.html
+++ b/docs/generated/changelog.html
@@ -10,6 +10,20 @@
Agent-JS Changelog
+ Version x.x.x
+
+ -
+ Adds a public method "createReadStateRequest" that creates the request for "readState".
+
+ -
+ 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.
+
+ -
+ Use the "createReadStateRequest" and the extra parameter when polling for the response to
+ avoid signing requests during polling.
+
+
Version 0.12.0
-
diff --git a/e2e/node/basic/basic.test.ts b/e2e/node/basic/basic.test.ts
index a085873f4..e42dae552 100644
--- a/e2e/node/basic/basic.test.ts
+++ b/e2e/node/basic/basic.test.ts
@@ -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({