Skip to content

Commit

Permalink
Merge branch 'main' into kai/remove-extend-function
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock authored Jun 5, 2024
2 parents d60703a + fa0404b commit 6b4811f
Show file tree
Hide file tree
Showing 18 changed files with 929 additions and 435 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: dfinity/conventional-pr-title-action@v3.2.0
- uses: dfinity/conventional-pr-title-action@v4.0.0
with:
success-state: Title follows the specification.
failure-state: Title does not follow the specification.
context-name: conventional-pr-title
preset: conventional-changelog-angular@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ commands to keep in mind;

The following scripts can be found in [./bin](./bin):

- update-management-idl - Update the management canister IDL in @dfinity/agent

Monorepo-related scripts run in this order, but are usually invoked by `npm install`:

- npm-postinstall - Run with `npm run postinstall` in this monorepo package.
Expand Down
49 changes: 49 additions & 0 deletions bin/update-management-idl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { $, cd, fetch } from 'zx';
import path from 'path';

fetch(
'https://raw.githubusercontent.com/dfinity/interface-spec/master/spec/_attachments/ic.did',
).then(async res => {
res.text().then(async text => {
const root = path.resolve(__dirname, '..');

const candid = text;

await cd(`${root}/packages/agent/src/canisters`);

await $`echo ${candid} > management.did`;
let ts = (await $`didc bind management.did -t ts`).toString();
let js = (await $`didc bind management.did -t js`).toString();

const didcVersion = await $`didc --version`;

const prefix = `/*
* This file is generated from the candid for asset management.
* didc version: ${didcVersion.toString().split(' ')[1].trim()}
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
`;

// replace first line of service

ts = ts.replace(`export interface _SERVICE {`, `export default interface _SERVICE {`);
js = js.replace(`export const idlFactory = ({ IDL }) => {`, `export default ({ IDL }) => {`);

// remove init function
js = js.split('export const init = ({ IDL }) => {')[0];

ts = prefix + ts;
js = prefix + js;

await $`echo ${js} > management_idl.ts`;
await $`echo ${ts} > management_service.ts`;

await cd(`${root}`);

await $`npm run prettier:format`;

console.log('Done!');
});
});
4 changes: 2 additions & 2 deletions demos/sample-javascript/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h1>Identity</h1>
<h2>Sign In</h2>
<div>
<label for="idpUrl" style="display: inline-block; width: 120px">Identity Provider: </label>
<input type="text" id="idpUrl" value="https://identity.messaging.ic0.app/#authorize" />
<input type="text" id="idpUrl" value="https://identity.ic0.app/" />
</div>
<button id="signinBtn">Sign In</button>
<button id="signoutBtn">Sign Out</button>
Expand All @@ -16,7 +16,7 @@ <h2>Principal:</h2>
<div>
<h1>Contact the IC</h1>
<label for="hostUrl" style="display: inline-block; width: 120px">Replica URL: </label>
<input type="text" id="hostUrl" value="https://gw.dfinity.network/" />
<input type="text" id="hostUrl" value="https://icp-api.io/" />
<br />
<label for="canisterId" style="display: inline-block; width: 120px">Canister ID: </label>
<input type="text" id="canisterId" value="4k2wq-cqaaa-aaaab-qac7q-cai" />
Expand Down
9 changes: 9 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

## [Unreleased]

### Added

- feat!: add support for proof of absence in Certificate lookups
- feat: `update-management-idl` automation to update the management canister IDL in `@dfinity/agent`

### Changed

- fix: ObservableLog no longer extends Function and class instance can no longer be called. Fixes an issue when running in a browser extension context.
- feat!: ObservableLog's `log` method is renamed to `print` to avoind calling `log.log`.
- chore: update management canister interface with latest bitcoin features
- fix: publish script will correctly update the `package-lock.json` file with the correct dependencies when making a new release
- chore: updates agent error response to read "Gateway returns error" instead of "Server"`
- chore: updates dfinity/conventional-pr-title-action to v4.0.0
- chore: updates dfinity/conventional-pr-title-action to v3.2.0

## [1.3.0] - 2024-05-01
Expand Down
38 changes: 29 additions & 9 deletions e2e/node/basic/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ActorMethod, Certificate, getManagementCanister } from '@dfinity/agent';
import {
ActorMethod,
Certificate,
LookupResultFound,
LookupStatus,
getManagementCanister,
} from '@dfinity/agent';
import { IDL } from '@dfinity/candid';
import { Principal } from '@dfinity/principal';
import agent from '../utils/agent';
Expand All @@ -18,14 +24,21 @@ test('read_state', async () => {
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)!;
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({ status: LookupStatus.Unknown });

let rawTime = cert.lookup(path);

expect(rawTime.status).toEqual(LookupStatus.Found);
rawTime = rawTime as LookupResultFound;

expect(rawTime.value).toBeInstanceOf(ArrayBuffer);
rawTime.value = rawTime.value as ArrayBuffer;

const decoded = IDL.decode(
[IDL.Nat],
new Uint8Array([
...new TextEncoder().encode('DIDL\x00\x01\x7d'),
...(new Uint8Array(rawTime) || []),
...(new Uint8Array(rawTime.value) || []),
]),
)[0];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -54,14 +67,21 @@ test('read_state with passed request', async () => {
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)!;
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({ status: LookupStatus.Unknown });

let rawTime = cert.lookup(path);

expect(rawTime.status).toEqual(LookupStatus.Found);
rawTime = rawTime as LookupResultFound;

expect(rawTime.value).toBeInstanceOf(ArrayBuffer);
rawTime.value = rawTime.value as ArrayBuffer;

const decoded = IDL.decode(
[IDL.Nat],
new Uint8Array([
...new TextEncoder().encode('DIDL\x00\x01\x7d'),
...(new Uint8Array(rawTime) || []),
...(new Uint8Array(rawTime.value) || []),
]),
)[0];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
79 changes: 49 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6b4811f

Please sign in to comment.