Skip to content

Commit

Permalink
Fix expiry in test-vector (#698)
Browse files Browse the repository at this point in the history
# Motivation

Expiry takes as a constructor argument the time _delta_ in millis.
Supplied was the absolute timestamp as a number (but too large to use
accurate integer representation).

This fixes the bug.

In addition, the test vector should be called ICRC-21 rather then
ICRC-29.

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Llorenç <[email protected]>
  • Loading branch information
3 people committed Oct 7, 2024
1 parent d8f3f1d commit fa83546
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 74 deletions.
4 changes: 2 additions & 2 deletions scripts/test-vectors/20220923-spawn-neuron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { createBlob, splitPrincipal, writeToJson } from "./utils";
const mockNeuronId = BigInt(15374508381553347371);
const mockNeuronId2 = BigInt(8836564053576662908);
const mockPrincipal = Principal.fromText(
"xlmdg-vkosz-ceopx-7wtgu-g3xmd-koiyc-awqaq-7modz-zf6r6-364rh-oqe"
"xlmdg-vkosz-ceopx-7wtgu-g3xmd-koiyc-awqaq-7modz-zf6r6-364rh-oqe",
);

const createCandidSpawnNeuron = ({
Expand Down Expand Up @@ -46,7 +46,7 @@ const createCandidSpawnNeuron = ({
? ["Controller : Self"]
: splitPrincipal(newController).map(
(data, i, elements) =>
`Controller [${i + 1}/${elements.length}] : ${data}`
`Controller [${i + 1}/${elements.length}] : ${data}`,
);

outputs.push(...controllerMessages);
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-vectors/20221206-increase-dd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const mockNeuronId2 = BigInt(8836564053576662908);

const createIncreaseDissolveDelayVector = (
neuronId: NeuronId,
additionalDissolveDelaySeconds: number
additionalDissolveDelaySeconds: number,
) => {
const params = {
neuronId,
Expand Down
13 changes: 7 additions & 6 deletions scripts/test-vectors/20230110-sns-add-hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ interface Params extends SnsNeuronPermissionsParams {
const createTestVector = (params: Params) => {
const rawRequestBody = toAddPermissionsRequest(params);
const canisterIdOutputs = splitPrincipal(params.canisterId).map(
(data, i, elements) => `Canister Id [${i + 1}/${elements.length}] : ${data}`
(data, i, elements) =>
`Canister Id [${i + 1}/${elements.length}] : ${data}`,
);
const neuronIdString = bytesToHexString(Array.from(params.neuronId.id));
const neuronIdOutputs =
Expand All @@ -44,14 +45,14 @@ const createTestVector = (params: Params) => {
}, [] as string[])
?.map(
(data, i, elements) =>
`Neuron Id [${i + 1}/${elements.length}] : ${data}`
`Neuron Id [${i + 1}/${elements.length}] : ${data}`,
) || [];
const principalOutputs = splitPrincipal(params.principal).map(
(data, i, elements) =>
`Principal Id [${i + 1}/${elements.length}] : ${data}`
`Principal Id [${i + 1}/${elements.length}] : ${data}`,
);
const permissionOutputs = params.permissions.map(
(p) => `Add Permission : ${permissionMapper[p]}`
(p) => `Add Permission : ${permissionMapper[p]}`,
);
const output = [
"Transaction type : Add Neuron Permissions",
Expand Down Expand Up @@ -86,10 +87,10 @@ const main = () => {
61,
]);
const principal1 = Principal.fromText(
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae"
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae",
);
const principal2 = Principal.fromText(
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe"
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe",
);
const canisterId1 = Principal.fromText("ppmzm-3aaaa-aaaaa-aacpq-cai");
const canisterId2 = Principal.fromText("s24we-diaaa-aaaaa-aaaka-cai");
Expand Down
15 changes: 9 additions & 6 deletions scripts/test-vectors/20230118-sns-manage-neuron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ interface DisburseParams extends SnsDisburseNeuronParams {
const createDisburseVector = (params: DisburseParams) => {
const rawRequestBody = toDisburseNeuronRequest(params);
const canisterIdOutputs = splitPrincipal(params.canisterId).map(
(data, i, elements) => `Canister Id [${i + 1}/${elements.length}] : ${data}`
(data, i, elements) =>
`Canister Id [${i + 1}/${elements.length}] : ${data}`,
);
const neuronIdString = bytesToHexString(Array.from(params.neuronId.id));
const neuronIdOutputs = splitString(neuronIdString, "Neuron Id");
const disburseToAccountStr = encodeIcrcAccount(
params.toAccount ?? {
owner: defaultCaller,
}
},
);
const disburseToOutputs = splitString(disburseToAccountStr, "Disburse to");
const amount = params.amount
Expand Down Expand Up @@ -73,7 +74,8 @@ interface SetDissolveParams {
const createStopDissolveVector = (params: SetDissolveParams) => {
const rawRequestBody = toStopDissolvingNeuronRequest(params.neuronId);
const canisterIdOutputs = splitPrincipal(params.canisterId).map(
(data, i, elements) => `Canister Id [${i + 1}/${elements.length}] : ${data}`
(data, i, elements) =>
`Canister Id [${i + 1}/${elements.length}] : ${data}`,
);
const neuronIdString = bytesToHexString(Array.from(params.neuronId.id));
const neuronIdOutputs = splitString(neuronIdString, "Neuron Id");
Expand All @@ -99,7 +101,8 @@ const createStopDissolveVector = (params: SetDissolveParams) => {
const createStartDissolveVector = (params: SetDissolveParams) => {
const rawRequestBody = toStartDissolvingNeuronRequest(params.neuronId);
const canisterIdOutputs = splitPrincipal(params.canisterId).map(
(data, i, elements) => `Canister Id [${i + 1}/${elements.length}] : ${data}`
(data, i, elements) =>
`Canister Id [${i + 1}/${elements.length}] : ${data}`,
);
const neuronIdString = bytesToHexString(Array.from(params.neuronId.id));
const neuronIdOutputs = splitString(neuronIdString, "Neuron Id");
Expand Down Expand Up @@ -134,10 +137,10 @@ const main = () => {
61,
]);
const principal1 = Principal.fromText(
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae"
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae",
);
const principal2 = Principal.fromText(
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe"
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe",
);
const snsAccount1 = {
owner: principal1,
Expand Down
11 changes: 6 additions & 5 deletions scripts/test-vectors/20230118-sns-remove-hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ interface Params extends SnsNeuronPermissionsParams {
const createTestVector = (params: Params) => {
const rawRequestBody = toRemovePermissionsRequest(params);
const canisterIdOutputs = splitPrincipal(params.canisterId).map(
(data, i, elements) => `Canister Id [${i + 1}/${elements.length}] : ${data}`
(data, i, elements) =>
`Canister Id [${i + 1}/${elements.length}] : ${data}`,
);
const neuronIdString = bytesToHexString(Array.from(params.neuronId.id));
const neuronIdOutputs = splitString(neuronIdString, "Neuron Id");
const principalOutputs = splitPrincipal(params.principal).map(
(data, i, elements) =>
`Principal Id [${i + 1}/${elements.length}] : ${data}`
`Principal Id [${i + 1}/${elements.length}] : ${data}`,
);
const permissionOutputs = params.permissions.map(
(p) => `Remove Permission : ${permissionMapper[p]}`
(p) => `Remove Permission : ${permissionMapper[p]}`,
);
const output = [
"Transaction type : Remove Neuron Permissions",
Expand Down Expand Up @@ -69,10 +70,10 @@ const main = () => {
61,
]);
const principal1 = Principal.fromText(
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae"
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae",
);
const principal2 = Principal.fromText(
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe"
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe",
);
const canisterId1 = Principal.fromText("ppmzm-3aaaa-aaaaa-aacpq-cai");
const canisterId2 = Principal.fromText("s24we-diaaa-aaaaa-aaaka-cai");
Expand Down
11 changes: 6 additions & 5 deletions scripts/test-vectors/20230123-icrc-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,23 @@ const createTestVector = (params: Params) => {

let outputTxType = isICP ? "Send ICP" : "Send Tokens";
const canisterIdOutputs = splitPrincipal(params.canisterId).map(
(data, i, elements) => `Canister Id [${i + 1}/${elements.length}] : ${data}`
(data, i, elements) =>
`Canister Id [${i + 1}/${elements.length}] : ${data}`,
);

const fromOutputs = splitAccount(
{
owner: params.owner,
subaccount: params.from_subaccount,
},
"From account"
"From account",
);
const toOutputs = splitAccount(
{
owner: params.to.owner,
subaccount: fromNullable(params.to.subaccount),
},
"To account"
"To account",
);

const amountToken = Number(params.amount) / Number(E8S_PER_TOKEN);
Expand Down Expand Up @@ -126,10 +127,10 @@ const main = () => {
61,
]);
const principal1 = Principal.fromText(
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae"
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae",
);
const principal2 = Principal.fromText(
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe"
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe",
);
const canisterId1 = Principal.fromText("ppmzm-3aaaa-aaaaa-aacpq-cai");
const canisterId2 = Principal.fromText("s24we-diaaa-aaaaa-aaaka-cai");
Expand Down
3 changes: 2 additions & 1 deletion scripts/test-vectors/20230125-sns-stake-maturity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ interface StakeMaturityParams extends SnsNeuronStakeMaturityParams {
const createStakeMaturityVector = (params: StakeMaturityParams) => {
const rawRequestBody = toStakeMaturityRequest(params);
const canisterIdOutputs = splitPrincipal(params.canisterId).map(
(data, i, elements) => `Canister Id [${i + 1}/${elements.length}] : ${data}`
(data, i, elements) =>
`Canister Id [${i + 1}/${elements.length}] : ${data}`,
);
const neuronIdString = bytesToHexString(Array.from(params.neuronId.id));
const neuronIdOutputs = splitString(neuronIdString, "Neuron Id");
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-vectors/20230321-disburse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const mockNeuronId2 = BigInt(8836564053576662908);
const amount1 = BigInt(20_000_000);
const amount2 = BigInt(25_000_000);
const account1 = AccountIdentifier.fromHex(
"d4685b31b51450508aff0331584df7692a84467b680326f5c5f7d30ae711682f"
"d4685b31b51450508aff0331584df7692a84467b680326f5c5f7d30ae711682f",
);
const account2 = AccountIdentifier.fromHex(
"b1cebc8480a0afc91198a87ddf52c6ca7eb7ccddb0cb398064f71d2bbaf2f72b"
"b1cebc8480a0afc91198a87ddf52c6ca7eb7ccddb0cb398064f71d2bbaf2f72b",
);

const createDisburseVector = ({
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-vectors/20230511-add-hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { createBlob, writeToJson } from "./utils";
const mockNeuronId = BigInt(15374508381553347371);
const mockNeuronId2 = BigInt(8836564053576662908);
const principal1 = Principal.fromText(
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae"
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae",
);
const principal2 = Principal.fromText(
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe"
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe",
);

const createAddHotkeyVector = ({
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-vectors/20230511-remove-hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { createBlob, writeToJson } from "./utils";
const mockNeuronId = BigInt(15374508381553347371);
const mockNeuronId2 = BigInt(8836564053576662908);
const principal1 = Principal.fromText(
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae"
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae",
);
const principal2 = Principal.fromText(
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe"
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe",
);

const createRemoveHotkeyVector = ({
Expand Down
12 changes: 6 additions & 6 deletions scripts/test-vectors/20230516-send-icp-stake-neuron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ import { TransferFn } from "./ledger.idl";
import { createBlob, writeToJson } from "./utils";

const account1 = AccountIdentifier.fromHex(
"d3e13d4777e22367532053190b6c6ccf57444a61337e996242b1abfb52cf92c8"
"d3e13d4777e22367532053190b6c6ccf57444a61337e996242b1abfb52cf92c8",
);
const account2 = AccountIdentifier.fromPrincipal({
principal: Principal.fromText(
"bwz3t-ercuj-owo6s-4adfr-sbu4o-l72hg-kfhc5-5sapm-tj6bn-3scho-uqe"
"bwz3t-ercuj-owo6s-4adfr-sbu4o-l72hg-kfhc5-5sapm-tj6bn-3scho-uqe",
),
});

const defaultCaller = Principal.fromText(
"5upke-tazvi-6ufqc-i3v6r-j4gpu-dpwti-obhal-yb5xj-ue32x-ktkql-rqe"
"5upke-tazvi-6ufqc-i3v6r-j4gpu-dpwti-obhal-yb5xj-ue32x-ktkql-rqe",
);
const caller1 = Principal.fromText(
"bwz3t-ercuj-owo6s-4adfr-sbu4o-l72hg-kfhc5-5sapm-tj6bn-3scho-uqe"
"bwz3t-ercuj-owo6s-4adfr-sbu4o-l72hg-kfhc5-5sapm-tj6bn-3scho-uqe",
);

const subaccount1 = [
Expand All @@ -50,7 +50,7 @@ const randomBytes3 = new Uint8Array([178, 247, 215, 62, 199, 137, 175, 189]);

const buildNeuronStakeSubAccount = (
nonce: Uint8Array,
principal: Principal
principal: Principal,
): SubAccount => {
const padding = asciiStringToByteArray("neuron-stake");
const shaObj = sha256.create();
Expand Down Expand Up @@ -104,7 +104,7 @@ const createSendIcpVector = ({
fromSubAccount === undefined
? undefined
: (SubAccount.fromBytes(
arrayOfNumberToUint8Array(fromSubAccount)
arrayOfNumberToUint8Array(fromSubAccount),
) as SubAccount);

return {
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-vectors/20230516-spawn-neuron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { createBlob, writeToJson } from "./utils";
const mockNeuronId = BigInt(15374508381553347371);
const mockNeuronId2 = BigInt(8836564053576662908);
const principal1 = Principal.fromText(
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae"
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae",
);
const principal2 = Principal.fromText(
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe"
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe",
);

const createSpawnNeuronVector = ({
Expand Down
11 changes: 6 additions & 5 deletions scripts/test-vectors/20230524-icrc-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,23 @@ const createTestVector = (params: Params) => {

let outputTxType = isICP ? "Send ICP" : "Send Tokens";
const canisterIdOutputs = splitPrincipal(params.canisterId).map(
(data, i, elements) => `Canister Id [${i + 1}/${elements.length}] : ${data}`
(data, i, elements) =>
`Canister Id [${i + 1}/${elements.length}] : ${data}`,
);

const fromOutputs = splitAccount(
{
owner: params.owner,
subaccount: params.from_subaccount,
},
"From account"
"From account",
);
const toOutputs = splitAccount(
{
owner: params.to.owner,
subaccount: fromNullable(params.to.subaccount),
},
"To account"
"To account",
);

const amountToken = Number(params.amount) / Number(E8S_PER_TOKEN);
Expand Down Expand Up @@ -126,10 +127,10 @@ const main = () => {
61,
]);
const principal1 = Principal.fromText(
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae"
"krpzt-buecq-u3umg-7kb7r-j5jpx-twqwa-3ykc4-y3cnk-7kwvw-5bq6z-mae",
);
const principal2 = Principal.fromText(
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe"
"2dfd6-abjpf-eihu7-pwv6m-qnlbt-oszmg-kb26q-rvqms-onmuh-mwiq3-uqe",
);
const canisterId1 = Principal.fromText("ppmzm-3aaaa-aaaaa-aacpq-cai");
const canisterId2 = Principal.fromText("s24we-diaaa-aaaaa-aaaka-cai");
Expand Down
10 changes: 5 additions & 5 deletions scripts/test-vectors/20230712-sns-set-dissolve-timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { SnsSetDissolveTimestampParams } from "@dfinity/sns/src";
import { toSetDissolveTimestampRequest } from "@dfinity/sns/src/converters/governance.converters";
import { arrayOfNumberToUint8Array } from "@dfinity/utils";
import {
secondsToDissolveDelayDuration,
SECONDS_IN_DAY,
SECONDS_IN_MONTH,
SECONDS_IN_YEAR,
secondsToDissolveDelayDuration,
} from "./date-utils";
import { ManageNeuronFn } from "./sns-governance.idl";
import { bytesToHexString, createBlob, writeToJson } from "./utils";
Expand All @@ -25,7 +25,7 @@ const createTestVector = (params: Params) => {
const rawRequestBody = toSetDissolveTimestampRequest(params);
const neuronIdString = bytesToHexString(Array.from(params.neuronId.id));
const timestampLabel = secondsToDissolveDelayDuration(
params.dissolveTimestampSeconds - BigInt(nowInSeconds)
params.dissolveTimestampSeconds - BigInt(nowInSeconds),
);
console.log("in da test vector", params.dissolveTimestampSeconds);
return {
Expand Down Expand Up @@ -58,15 +58,15 @@ const main = () => {
const canisterId2 = Principal.fromText("s24we-diaaa-aaaaa-aaaka-cai");
const inOneYear = BigInt(nowInSeconds + SECONDS_IN_YEAR);
const nextYearAndAHalf = BigInt(
Math.round(nowInSeconds + SECONDS_IN_YEAR + SECONDS_IN_MONTH * 6)
Math.round(nowInSeconds + SECONDS_IN_YEAR + SECONDS_IN_MONTH * 6),
);
const inOneYearMonthsAndDays = BigInt(
Math.round(
nowInSeconds +
SECONDS_IN_YEAR +
SECONDS_IN_MONTH * 3 +
SECONDS_IN_DAY * 18
)
SECONDS_IN_DAY * 18,
),
);
const inSixMonths = BigInt(Math.round(nowInSeconds + SECONDS_IN_MONTH * 6));
const inEightYears = BigInt(Math.round(nowInSeconds + SECONDS_IN_YEAR * 8));
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-vectors/20230927-icrc-stake-neuron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const createTestVector = (params: Params) => {
let outputTxType = isStakeNeuron
? "Stake Neuron"
: isICP
? "Send ICP"
: "Send Tokens";
? "Send ICP"
: "Send Tokens";
const canisterIdOutputs = splitPrincipal(params.canisterId).map(
(data, i, elements) =>
`Canister Id [${i + 1}/${elements.length}] : ${data}`,
Expand Down
Loading

0 comments on commit fa83546

Please sign in to comment.