Skip to content

Commit 3655d04

Browse files
committed
test reproducibility
1 parent 525fa6b commit 3655d04

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

packages/agent/src/agent/http/__snapshots__/http.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`error logs for bad signature should do 1`] = `"{"message":"Error while making call:","level":"error","error":{"name":"AgentError","response":{},"requestId":"ab85c18a1bbca648f5a1e4b47b5b6829edae78cac384f8a52c8a8cf56a593532","sender_pubkey":"302a300506032b6570032100805206462aad05469a783b3f9f3d2e7a7e56a514f119dd75fe45681c0c4849df","sender_sig":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}}"`;
3+
exports[`error logs for bad signature should do 1`] = `"{"message":"Error while making call:","level":"error","error":{"name":"AgentError","response":{},"requestId":"803cec3065e120bab99d241c6b3f3439e5601acd10ba491e1d06fdbd39ae2fd3","sender_pubkey":"302a300506032b65700321003b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29","sender_sig":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}}"`;
44

55
exports[`it should handle calls against the ic-management canister that succeed 1`] = `
66
{

packages/agent/src/agent/http/errors.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { RequestId } from 'src/request_id';
21
import { AgentError } from '../../errors';
32
import { HttpDetailsResponse } from '../api';
4-
import { PublicKey, Signature } from 'src/auth';
53

64
export class AgentHTTPResponseError extends AgentError {
75
constructor(

packages/agent/src/agent/http/http.test.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,9 @@ describe('error logs for bad signature', () => {
10751075
);
10761076
});
10771077

1078-
jest.useRealTimers();
1079-
// jest.setSystemTime(badSignatureResponse.now);
1080-
const identity = Ed25519KeyIdentity.generate() as unknown as SignIdentity;
1078+
jest.useFakeTimers();
1079+
jest.setSystemTime(badSignatureResponse.now);
1080+
const identity = Ed25519KeyIdentity.generate(new Uint8Array(32)) as unknown as SignIdentity;
10811081
identity.sign = async () => {
10821082
return new ArrayBuffer(64) as Signature;
10831083
};
@@ -1086,14 +1086,15 @@ describe('error logs for bad signature', () => {
10861086
fetch: mockFetch,
10871087
host: 'http://localhost:4943',
10881088
});
1089+
// Important - override nonce when making request to ensure reproducible result
1090+
agent.addTransform('update', async args => {
1091+
args.body.nonce = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]) as Nonce;
1092+
return args;
1093+
});
10891094
const canisterId: Principal = Principal.fromText('2chl6-4hpzw-vqaaa-aaaaa-c');
10901095

10911096
const methodName = 'greet';
10921097
const arg = new Uint8Array([]);
1093-
1094-
jest.spyOn(Date, 'now').mockImplementation(() => {
1095-
return 1738280418227;
1096-
});
10971098
const logs: {
10981099
message: string;
10991100
level: 'error';

packages/agent/src/agent/http/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { JsonObject } from '@dfinity/candid';
22
import { Principal } from '@dfinity/principal';
33
import { AgentError } from '../../errors';
4-
import { AnonymousIdentity, Identity, Signature } from '../../auth';
4+
import { AnonymousIdentity, Identity } from '../../auth';
55
import * as cbor from '../../cbor';
66
import { RequestId, hashOfMap, requestIdOf } from '../../request_id';
77
import { bufFromBufLike, concat, fromHex, toHex } from '../../utils/buffer';

0 commit comments

Comments
 (0)