Skip to content

Commit

Permalink
various cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Mar 25, 2024
1 parent 4f5f1f1 commit 06a1776
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 33 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ jobs:
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }}
shell: bash -l {0}
working-directory: ${{ matrix.example_directories }}
run: mv /home/runner/.config/azle/wasmedge-quickjs "/home/runner/.config/azle/wasmedge-quickjs_$(npx azle dockerfile-hash)"
run: |
# TODO remove the echo just for testing
echo "/home/runner/.config/azle/wasmedge-quickjs_$(npx azle dockerfile-hash)"
mv /home/runner/.config/azle/wasmedge-quickjs "/home/runner/.config/azle/wasmedge-quickjs_$(npx azle dockerfile-hash)"
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests && !contains(github.head_ref, 'release--') && !(github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'Merge pull request') && contains(github.event.head_commit.message, 'demergent-labs/release--')) }}
shell: bash -l {0}
working-directory: ${{ matrix.example_directories }}
Expand Down
1 change: 0 additions & 1 deletion examples/ethers_base/dfx.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"canisters": {
"server": {
"specified_id": "bd3sg-teaaa-aaaaa-qaaba-cai",
"type": "custom",
"main": "src/server.ts",
"candid": "src/server.did",
Expand Down
4 changes: 2 additions & 2 deletions examples/ethers_base/src/server.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
service: () -> {
http_request: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}; certificate_version:opt nat16}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:record {}; callback:func (record {}) -> (opt record {token:opt record {}; body:vec nat8}) query}}; status_code:nat16}) query;
http_request_update: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}; certificate_version:opt nat16}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:record {}; callback:func (record {}) -> (opt record {token:opt record {}; body:vec nat8}) query}}; status_code:nat16});
http_request: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}; certificate_version:opt nat16}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:vec nat8; callback:func (vec nat8) -> (opt record {token:opt vec nat8; body:vec nat8}) query}}; status_code:nat16}) query;
http_request_update: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:vec nat8; callback:func (vec nat8) -> (opt record {token:opt vec nat8; body:vec nat8}) query}}; status_code:nat16});
}
2 changes: 1 addition & 1 deletion examples/ethers_base/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// If 0x9Ac70EE21bE697173b74aF64399d850038697FD3 ever runs out of Base ETH or USDC,
// just use a faucet like https://www.ethereum-ecosystem.com/faucets/base-sepolia to get some more
// We should be good for many thousands of tests
// We should be good for a few hundred tests

import * as dns from 'node:dns';
dns.setDefaultResultOrder('ipv4first');
Expand Down
1 change: 0 additions & 1 deletion examples/http_outcall_fetch/dfx.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"canisters": {
"server": {
"specified_id": "bd3sg-teaaa-aaaaa-qaaba-cai",
"type": "custom",
"main": "src/server.ts",
"candid": "src/server.did",
Expand Down
4 changes: 2 additions & 2 deletions server.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
service: () -> {
http_request: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}; certificate_version:opt nat16}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:record {}; callback:func (record {}) -> (opt record {token:opt record {}; body:vec nat8}) query}}; status_code:nat16}) query;
http_request_update: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}; certificate_version:opt nat16}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:record {}; callback:func (record {}) -> (opt record {token:opt record {}; body:vec nat8}) query}}; status_code:nat16});
http_request: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}; certificate_version:opt nat16}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:vec nat8; callback:func (vec nat8) -> (opt record {token:opt vec nat8; body:vec nat8}) query}}; status_code:nat16}) query;
http_request_update: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:vec nat8; callback:func (vec nat8) -> (opt record {token:opt vec nat8; body:vec nat8}) query}}; status_code:nat16});
}
8 changes: 3 additions & 5 deletions src/lib/fetch/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { inflate } from 'pako';

import { azleFetch, serialize } from '.';
import { ic } from '../';
import { HttpTransform } from '../../../canisters/management';
import { AzleFetchResponse } from './response';
import { getUrl } from './url';

Expand Down Expand Up @@ -93,7 +94,7 @@ export async function fetchHttp(
});
}

function getHttpMaxResponseBytes() {
function getHttpMaxResponseBytes(): [] | [bigint] {
return globalThis._azleOutgoingHttpOptionsMaxResponseBytes === undefined
? []
: [globalThis._azleOutgoingHttpOptionsMaxResponseBytes];
Expand Down Expand Up @@ -127,7 +128,7 @@ function getHttpMethod(init?: RequestInit | undefined) {
};
}

function getHttpTransform() {
function getHttpTransform(): [] | [HttpTransform] {
if (globalThis._azleOutgoingHttpOptionsTransformMethodName === undefined) {
return [];
}
Expand Down Expand Up @@ -172,9 +173,6 @@ function getCycles(
const totalFeeEstimate =
baseFeeEstimate + requestFeeEstimate + responseFeeEstimate;

// TODO this calculation appears to be very correct according to the documentation
// TODO but it is producing an amount ~20x more than what the system actually asks for
// TODO Hopefully this gets resolved soon: https://forum.dfinity.org/t/a-new-price-function-for-https-outcalls/20838/20
return globalThis._azleOutgoingHttpOptionsCycles ?? totalFeeEstimate;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ function logWarnings(init?: RequestInit | undefined) {

function logWarning(method: string) {
console.warn(
`fetchIc: init.${method} has no effect when using an identity as the Authorization header`
`azleFetch: init.${method} has no effect when using an identity as the Authorization header`
);
}
16 changes: 11 additions & 5 deletions src/lib/fetch/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ export class AzleFetchResponse {
this.status = init?.status ?? 200;
this.statusText = getStatusText(this.status);
this.ok = this.status >= 200 && this.status <= 299;
this.type = 'default'; // TODO determine this
this.redirected = false; //TODO determine this
this.bodyUsed = false; // TODO determine this
this.type = '' as any; // TODO we should work to set this appropriately
this.redirected = false; // TODO we are defaulting to false, I believe we would have to implement automatic redirects for this to ever be true
this.bodyUsed = false;
this.headers = new AzleFetchHeaders(init?.headers);
this.url = ''; // TODO where are we supposed to get this from?
this.url = ''; // TODO I do not understand how this is supposed to be set, as it is a readon-only property and the Respone constructor does not allow you to pass in the URL
}

async arrayBuffer(): Promise<ArrayBuffer> {
this.bodyUsed = true;

if (this.body === null) {
return new ArrayBuffer(0);
}
Expand All @@ -38,8 +40,10 @@ export class AzleFetchResponse {
}

async json(): Promise<string> {
this.bodyUsed = true;

if (this.body === null) {
return ''; // TODO is this correct?
return JSON.parse('');
}

return JSON.parse(
Expand All @@ -48,6 +52,8 @@ export class AzleFetchResponse {
}

async text(): Promise<string> {
this.bodyUsed = true;

if (this.body === null) {
return '';
}
Expand Down
14 changes: 1 addition & 13 deletions src/lib/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,9 @@ if (globalThis._azleInsideCanister) {
handler: TimerHandler,
timeout?: number
) => {
// if (timeout === undefined || timeout === 0) {
// return originalSetTimeout(handler, 0);
// }

// console.warn

// throw new Error()

// TODO change this to throw once errors throw and show up properly
// TODO should this throw an error or just not do anything? At least a warning would be good right?
// ic.trap(`setTimeout cannot be called with milliseconds above 0`);

if (timeout !== undefined && timeout !== 0) {
console.warn(
`Azle Warning: setTimeout should not be called with milliseconds above 0, called with ${timeout} milliseconds`,
`Azle Warning: setTimeout may not behave as expected with milliseconds above 0; called with ${timeout} milliseconds`,
new Error().stack
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/threshold_wallet/calculate_rsv_for_tecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ export function calculateRsvForTEcdsa(
return rsv1;
}

throw new Error(`v could not be calculated correctly`);
throw new Error(`ThresholdWallet: v could not be calculated correctly`);
}

0 comments on commit 06a1776

Please sign in to comment.