diff --git a/e2e/node/utils/agent.ts b/e2e/node/utils/agent.ts index 4eef883ae..718bab5d9 100644 --- a/e2e/node/utils/agent.ts +++ b/e2e/node/utils/agent.ts @@ -12,6 +12,8 @@ if (Number.isNaN(port)) { export const makeAgent = async (options?: HttpAgentOptions) => { const agent = new HttpAgent({ host: `http://127.0.0.1:${process.env.REPLICA_PORT ?? 4943}`, + // TODO - remove this when the dfx replica supports it + verifyQuerySignatures: false, ...options, }); try { diff --git a/packages/agent/src/actor.test.ts b/packages/agent/src/actor.test.ts index 406e1b9b1..972ffb217 100644 --- a/packages/agent/src/actor.test.ts +++ b/packages/agent/src/actor.test.ts @@ -337,18 +337,4 @@ describe('makeActor', () => { ); }); }); - -test('whoami', async () => { - jest.useRealTimers(); - const agent = new HttpAgent({ host: 'https://icp-api.io' }); - const idl = () => - IDL.Service({ - whoami: IDL.Func([], [IDL.Principal], ['query']), - }); - const canisterId = Principal.fromText('ivcos-eqaaa-aaaab-qablq-cai'); - const actor = Actor.createActor(idl, { canisterId, agent }); - - const result = await actor.whoami(); -}); - // TODO: tests for rejected, unknown time out diff --git a/packages/agent/src/agent/http/index.ts b/packages/agent/src/agent/http/index.ts index 547c07091..fde205677 100644 --- a/packages/agent/src/agent/http/index.ts +++ b/packages/agent/src/agent/http/index.ts @@ -559,7 +559,7 @@ export class HttpAgent implements Agent { const { reply } = queryResponse; hash = hashOfMap({ status: status, - reply: hashOfMap(reply), + reply: reply, timestamp: BigInt(timestamp), request_id: requestId, }); diff --git a/packages/agent/src/certificate.test.ts b/packages/agent/src/certificate.test.ts index 5f537e2eb..06b8f2fe0 100644 --- a/packages/agent/src/certificate.test.ts +++ b/packages/agent/src/certificate.test.ts @@ -131,7 +131,7 @@ test('lookup', () => { ).toEqual('world'); expect(Cert.lookup_path([fromText('aa')], tree)).toEqual(undefined); expect(Cert.lookup_path([fromText('ax')], tree)).toEqual(undefined); - expect(Cert.lookup_path([fromText('b')], tree)).toEqual(undefined); + expect(Cert.lookup_path([fromText('b')], tree)).toEqual([4, new ArrayBuffer(0)]); expect(Cert.lookup_path([fromText('bb')], tree)).toEqual(undefined); expect(toText(lookupResultToBuffer(Cert.lookup_path([fromText('d')], tree))!)).toEqual('morning'); expect(Cert.lookup_path([fromText('e')], tree)).toEqual(undefined); diff --git a/packages/agent/src/request_id.test.ts b/packages/agent/src/request_id.test.ts index 63210c035..7ca6d3902 100644 --- a/packages/agent/src/request_id.test.ts +++ b/packages/agent/src/request_id.test.ts @@ -135,9 +135,13 @@ describe('hashValue', () => { const value = hashValue(BigInt(7)); expect(value instanceof ArrayBuffer).toBe(true); }); + it('should hash objects using HashOfMap on their contents', () => { + const value = hashValue({ foo: 'bar' }); + expect(value instanceof ArrayBuffer).toBe(true); + }); it('should throw otherwise', () => { const shouldThrow = () => { - hashValue({ foo: 'bar' }); + hashValue(() => undefined); }; expect(shouldThrow).toThrowError('Attempt to hash'); }); diff --git a/packages/agent/src/request_id.ts b/packages/agent/src/request_id.ts index 127f4fd3f..88f504b84 100644 --- a/packages/agent/src/request_id.ts +++ b/packages/agent/src/request_id.ts @@ -47,6 +47,8 @@ export function hashValue(value: unknown): ArrayBuffer { // the flow to be synchronous to ensure Safari touch id works. // } else if (value instanceof Promise) { // return value.then(x => hashValue(x)); + } else if (typeof value === 'object') { + return hashOfMap(value as Record); } else if (typeof value === 'bigint') { // Do this check much later than the other bigint check because this one is much less // type-safe.