Skip to content

Commit

Permalink
Merge branch 'main' into kai/bls-verify
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock authored Mar 25, 2024
2 parents 21ba2aa + c4c9ef9 commit 3dc449e
Show file tree
Hide file tree
Showing 31 changed files with 1,154 additions and 482 deletions.
6 changes: 5 additions & 1 deletion bin/roll-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ if (!newVersion) {
process.exit(1);
}
const now = new Date();
const formattedDate = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
const padNumber = (num: number) => num.toString().padStart(2, '0');

const formattedDate = `${now.getFullYear()}-${padNumber(now.getMonth() + 1)}-${padNumber(
now.getDate(),
)}`;

const path: string = 'docs/CHANGELOG.md';
const pattern: string = '## [Unreleased]';
Expand Down
40 changes: 40 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@

## [Unreleased]

### Added

* feat: adds support for verified queries against management canister
* includes support for `fetch_canister_logs` in the actor provided by `getManagementCanister`
* also includes support for bitcoin queries

Logging

```ts
// Agent should not use an anonymous identity for this call, and should ideally be a canister controller
const management = await getManagementCanister({ agent });
const logs = await management.fetch_canister_logs({ canister_id: canisterId });
```

Bitcoin

```ts
// For now, the verifyQuerySignatures option must be set to false
const agent = await makeAgent({ host: 'https://icp-api.io', verifyQuerySignatures: false });
const management = getManagementCanister({
agent
});

const result = await management.bitcoin_get_balance_query({
address: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
network: { mainnet: null },
min_confirmations: [6],
});
```

### Changed

* fix: pads date numbers in changelog automation. E.G. 2024-3-1 -> 2024-03-01
* feat: allow passing `DBCreateOptions` to `IdbStorage` constructor
* updated management canister interface

## [1.1.1] - 2024-03-19

* fix: work around `PublicKeyCredential` not being enumerable

## [1.1.0] - 2024-03-18

### Added
Expand Down
8 changes: 4 additions & 4 deletions e2e/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@do-not-publish/ic-cypress-e2e-tests",
"version": "1.1.0",
"version": "1.1.1",
"scripts": {
"ci": "npm run e2e",
"setup": "dfx deploy; dfx generate; pm2 --name parcel start npm -- start",
Expand All @@ -27,9 +27,9 @@
"size-limit": "^8.1.0"
},
"dependencies": {
"@dfinity/agent": "^1.1.0",
"@dfinity/identity": "^1.1.0",
"@dfinity/principal": "^1.1.0",
"@dfinity/agent": "^1.1.1",
"@dfinity/identity": "^1.1.1",
"@dfinity/principal": "^1.1.1",
"idb-keyval": "^6.2.0"
},
"optionalDependencies": {
Expand Down
31 changes: 31 additions & 0 deletions e2e/node/basic/logging.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { bufFromBufLike, getManagementCanister } from '@dfinity/agent';
import { describe, it, expect } from 'vitest';
import logsActor from '../canisters/logs';
import { makeAgent } from '../utils/agent';

describe('canister logs', () => {
it('should make requests to the management canister', async () => {
const { canisterId } = await logsActor();

const management = await getManagementCanister({ agent: await makeAgent() });
const logs = await management.fetch_canister_logs({ canister_id: canisterId });

expect(logs.canister_log_records.length).toBe(1);
const content = bufFromBufLike(logs.canister_log_records[0].content);

expect(new TextDecoder().decode(content).trim()).toBe('Hello, first call!');
});
it('should show additional logs', async () => {
const { canisterId, actor } = await logsActor();

await actor.hello('second call');

const management = await getManagementCanister({ agent: await makeAgent() });
const logs = await management.fetch_canister_logs({ canister_id: canisterId });

expect(logs.canister_log_records.length).toBe(2);
const content = bufFromBufLike(logs.canister_log_records[1].content);

expect(new TextDecoder().decode(content).trim()).toBe('Hello, second call!');
});
}, 10_000);
27 changes: 26 additions & 1 deletion e2e/node/basic/mainnet.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Actor, AnonymousIdentity, HttpAgent, Identity, CanisterStatus } from '@dfinity/agent';
import {
Actor,
AnonymousIdentity,
HttpAgent,
Identity,
CanisterStatus,
getManagementCanister,
} from '@dfinity/agent';
import { IDL } from '@dfinity/candid';
import { Ed25519KeyIdentity } from '@dfinity/identity';
import { Principal } from '@dfinity/principal';
Expand Down Expand Up @@ -161,3 +168,21 @@ describe('controllers', () => {
`);
});
});

describe('bitcoin query', async () => {
it('should return the balance of a bitcoin address', async () => {
// TODO - verify node signature for bitcoin once supported
const agent = await makeAgent({ host: 'https://icp-api.io', verifyQuerySignatures: false });
const management = getManagementCanister({
agent,
});

const result = await management.bitcoin_get_balance_query({
address: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
network: { mainnet: null },
min_confirmations: [6],
});
console.log(`balance for address: ${result}`);
expect(result).toBeGreaterThan(0n);
});
});
1 change: 1 addition & 0 deletions e2e/node/basic/mitm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mitmTest(
const counter = await createActor('tnnnb-2yaaa-aaaab-qaiiq-cai', {
agent: await makeAgent({
host: 'http://127.0.0.1:8888',
verifyQuerySignatures: false,
}),
});
await expect(counter.greet('counter')).rejects.toThrow(/Invalid certificate/);
Expand Down
52 changes: 52 additions & 0 deletions e2e/node/canisters/logs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Principal } from '@dfinity/principal';
import agent from '../utils/agent';
import { readFileSync } from 'fs';
import path from 'path';
import { Actor, ActorMethod, ActorSubclass } from '@dfinity/agent';
import { IDL } from '@dfinity/candid';

export interface _SERVICE {
hello: ActorMethod<[string], undefined>;
}
export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];

export const idlFactory = ({ IDL }) => {
return IDL.Service({ hello: IDL.Func([IDL.Text], [], []) });
};

let cache: {
canisterId: Principal;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
actor: any;
} | null = null;

/**
* Create a counter Actor + canisterId
*/
export default async function (): Promise<{
canisterId: Principal;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
actor: any;
}> {
if (!cache) {
const module = readFileSync(path.join(__dirname, 'logs.wasm'));

const canisterId = await Actor.createCanister({ agent: await agent });
await Actor.install({ module }, { canisterId, agent: await agent });

const actor = Actor.createActor(idlFactory, {
canisterId,
agent: await agent,
}) as ActorSubclass<_SERVICE>;

await actor.hello('first call');

cache = {
canisterId,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
actor,
};
}

return cache;
}
Binary file added e2e/node/canisters/logs.wasm
Binary file not shown.
10 changes: 5 additions & 5 deletions e2e/node/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@do-not-publish/ic-node-e2e-tests",
"version": "1.1.0",
"version": "1.1.1",
"type": "module",
"scripts": {
"ci": "npm run e2e",
Expand All @@ -16,10 +16,10 @@
"test": ""
},
"dependencies": {
"@dfinity/agent": "^1.1.0",
"@dfinity/assets": "^1.1.0",
"@dfinity/identity": "^1.1.0",
"@dfinity/principal": "^1.1.0",
"@dfinity/agent": "^1.1.1",
"@dfinity/assets": "^1.1.1",
"@dfinity/identity": "^1.1.1",
"@dfinity/principal": "^1.1.1",
"whatwg-fetch": "^3.6.2"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions e2e/node/utils/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ 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 {
Expand Down
Loading

0 comments on commit 3dc449e

Please sign in to comment.