Skip to content

Commit e17086b

Browse files
Merge pull request #1052 from ProvableHQ/rr-fixed-transition-decryption-tests
fixed tests
2 parents e369b2a + 79ad42b commit e17086b

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

sdk/tests/wasm.test.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from "chai";
2-
import { Address, Field, PrivateKey, ViewKey, Signature, RecordCiphertext, RecordPlaintext, PrivateKeyCiphertext, EncryptionToolkit, Transition } from "../src/node.js";
2+
import { Address, AleoNetworkClient, Field, PrivateKey, ViewKey, Signature, RecordCiphertext, RecordPlaintext, PrivateKeyCiphertext, EncryptionToolkit, Transition } from "../src/node.js";
33
import {
44
seed,
55
message,
@@ -381,34 +381,65 @@ describe('WASM Objects', () => {
381381
});
382382

383383
describe('Transition', () => {
384-
const transitionString = `{"id":"au1u62jasyx78x9hktak24awyj38fz73aseq8g9cx98u8egd9pj9uxq3u6s2z","program":"hello_hello.aleo","function":"hello","inputs":[{"type":"public","id":"3748790614260807060977840590007893602934308327222309419419577452790958781330field","value":"1u32"},{"type":"private","id":"5954208307642819953251922459490586292095132973876550778604572231610245257004field","value":"ciphertext1qyq0m5mp0d2gzh2pv9p25z70gz2avhqdt3dp8y8thzwf3aq6g35zcqcuyptz3"}],"outputs":[{"type":"private","id":"1557506318887190915592751299113729867877933642317637206076176689093854281418field","value":"ciphertext1qyqzmhw8ln9r6uuyh0n5jrsqlt25wdggqp3d9yqyttpr3g7g00k2sysdf9rmv"}],"tpk":"7532444547840484531569841377269810017844130178606467837628364672670182422388group","tcm":"7292056195970541935877520517416922164990366931599720071937561392936678536563field","scm":"8283770351301010771186520129040704279224805960417079922462917369178354050332field"}`;
385-
const transition = Transition.fromString(transitionString);
386-
const transitionDecryptedString = `{"id":"au1mhdz6jqm973v5vfkz2pwgv63p340c9tpvydxha2zs8w03746qcpqvx3yye","program":"hello_hello.aleo","function":"hello","inputs":[{"type":"public","id":"3748790614260807060977840590007893602934308327222309419419577452790958781330field","value":"1u32"},{"type":"public","id":"5954208307642819953251922459490586292095132973876550778604572231610245257004field","value":"2u32"}],"outputs":[{"type":"public","id":"1557506318887190915592751299113729867877933642317637206076176689093854281418field","value":"3u32"}],"tpk":"7532444547840484531569841377269810017844130178606467837628364672670182422388group","tcm":"7292056195970541935877520517416922164990366931599720071937561392936678536563field","scm":"8283770351301010771186520129040704279224805960417079922462917369178354050332field"}`
387-
const transitionDecrypted = Transition.fromString(transitionDecryptedString);
384+
const transitionStringTestnet = `{"id":"au1u62jasyx78x9hktak24awyj38fz73aseq8g9cx98u8egd9pj9uxq3u6s2z","program":"hello_hello.aleo","function":"hello","inputs":[{"type":"public","id":"3748790614260807060977840590007893602934308327222309419419577452790958781330field","value":"1u32"},{"type":"private","id":"5954208307642819953251922459490586292095132973876550778604572231610245257004field","value":"ciphertext1qyq0m5mp0d2gzh2pv9p25z70gz2avhqdt3dp8y8thzwf3aq6g35zcqcuyptz3"}],"outputs":[{"type":"private","id":"1557506318887190915592751299113729867877933642317637206076176689093854281418field","value":"ciphertext1qyqzmhw8ln9r6uuyh0n5jrsqlt25wdggqp3d9yqyttpr3g7g00k2sysdf9rmv"}],"tpk":"7532444547840484531569841377269810017844130178606467837628364672670182422388group","tcm":"7292056195970541935877520517416922164990366931599720071937561392936678536563field","scm":"8283770351301010771186520129040704279224805960417079922462917369178354050332field"}`;
385+
const transitionTestnet = Transition.fromString(transitionStringTestnet);
386+
const transitionDecryptedStringTestnet = `{"id":"au1mhdz6jqm973v5vfkz2pwgv63p340c9tpvydxha2zs8w03746qcpqvx3yye","program":"hello_hello.aleo","function":"hello","inputs":[{"type":"public","id":"3748790614260807060977840590007893602934308327222309419419577452790958781330field","value":"1u32"},{"type":"public","id":"5954208307642819953251922459490586292095132973876550778604572231610245257004field","value":"2u32"}],"outputs":[{"type":"public","id":"1557506318887190915592751299113729867877933642317637206076176689093854281418field","value":"3u32"}],"tpk":"7532444547840484531569841377269810017844130178606467837628364672670182422388group","tcm":"7292056195970541935877520517416922164990366931599720071937561392936678536563field","scm":"8283770351301010771186520129040704279224805960417079922462917369178354050332field"}`
387+
const transitionDecryptedTestnet = Transition.fromString(transitionDecryptedStringTestnet);
388+
const transitionViewKeyStringTestnet = "3975242887442171718863200089461896014344887434842278474302914755871123010247field";
389+
390+
const transitionStringMainnet = `{"id":"au1mguuz0dh20f78802m4z0py7n08xhl0pz60llzck63mhl8pc8l5xqxpwgtn","program":"hello_hello.aleo","function":"main","inputs":[{"type":"public","id":"6393584049543470937057043098611271993206122889317039351966319038535020834557field","value": "1u32"},{"type":"private","id":"8207446256045172951742235001162005156507562935942883128759030124682934277495field","value":"ciphertext1qyqqgz9qnupeld9vr4vuwp6yrpmhgtkvmgag5m7mmrruw0r6je666qgqdswk3"}],"outputs":[{"type":"private","id":"127469473292952941321346770257126666363371158501875622169294663492714835110field","value":"ciphertext1qyqyapkjuxm9dcslgyjf7hkr2k3dek500z40gjspnwvll0uawj23vzgggc405"}],"tpk":"7647553513996966044119163122930125808381703910407273818947266861843062002251group","tcm":"4479413938380109857414238205380483440836495997450846894155088299187217672609field","scm":"6461007226176477784737642021400489186736987671609840640950580467598882134642field"}`;
391+
const transitionMainnet = Transition.fromString(transitionStringMainnet);
392+
const transitionDecryptedStringMainnet = `{"id":"au1jl2ur42sj7hwe4r0alv6gnklqxj0fszrvu3q82gjcls5x6q9pyzqdgmu2k","program":"hello_hello.aleo","function":"main","inputs":[{"type":"public","id":"6393584049543470937057043098611271993206122889317039351966319038535020834557field","value":"1u32"},{"type":"public","id":"8207446256045172951742235001162005156507562935942883128759030124682934277495field","value":"2u32"}],"outputs":[{"type":"public","id":"127469473292952941321346770257126666363371158501875622169294663492714835110field","value":"3u32"}],"tpk":"7647553513996966044119163122930125808381703910407273818947266861843062002251group","tcm":"4479413938380109857414238205380483440836495997450846894155088299187217672609field","scm":"6461007226176477784737642021400489186736987671609840640950580467598882134642field"}`;
393+
const transitionDecryptedMainnet = Transition.fromString(transitionDecryptedStringMainnet);
394+
const transitionViewKeyStringMainnet = "8161419549946991944867064830365679191883723972221767444308198038592561311302field";
395+
388396
const invalidTransitionViewKeyString = "5089075468761042335883809641276568724119791331127957254389204093712358605127field"
389397
const invalidTransitionViewKey = Field.fromString(invalidTransitionViewKeyString);
390398
const privateKey = PrivateKey.from_string("APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH");
391399
const viewKey = privateKey.to_view_key();
392-
const tvk = transition.tvk(viewKey);
393400

401+
let connection = new AleoNetworkClient("https://api.explorer.provable.com/v1");
402+
403+
if (connection.network === "testnet") {
394404
it('can be decrypted with a valid transition view key', () => {
395-
const transitionDecryptedWithTVK = transition.decryptTransition(tvk);
405+
const tvk = transitionTestnet.tvk(viewKey);
406+
const transitionDecryptedWithTVK = transitionTestnet.decryptTransition(tvk);
396407
// Ensure the transition is valid
397-
expect(transitionDecryptedWithTVK.toString()).equal(transitionDecrypted.toString());
408+
expect(transitionDecryptedWithTVK.toString()).equal(transitionDecryptedTestnet.toString());
398409
});
399410

400411
it('cannot be decrypted with an invalid transition view key', () => {
401-
expect(() => transition.decryptTransition(invalidTransitionViewKey).toThrow());
412+
expect(() => transitionTestnet.decryptTransition(invalidTransitionViewKey).toThrow());
402413
});
403414

404415
it('can generate a transition view key from a valid view key', () => {
405-
const generatedTransitionViewKey = transition.tvk(viewKey);
416+
const generatedTransitionViewKey = transitionTestnet.tvk(viewKey);
406417

407-
const generatedTransitionViewKeyFromEncryptionToolkit = EncryptionToolkit.generateTvk(viewKey, transition.tpk());
408418
// Ensure the generated transition view key is the same as the one used to decrypt
409-
expect(generatedTransitionViewKey.toString()).equal(generatedTransitionViewKeyFromEncryptionToolkit.toString());
419+
expect(generatedTransitionViewKey.toString()).equal(transitionViewKeyStringTestnet);
410420
});
411-
});
421+
}
422+
if (connection.network === "mainnet") {
423+
const tvk = transitionMainnet.tvk(viewKey);
424+
it('can be decrypted with a valid transition view key', () => {
425+
const transitionDecryptedWithTVK = transitionMainnet.decryptTransition(tvk);
426+
// Ensure the transition is valid
427+
expect(transitionDecryptedWithTVK.toString()).equal(transitionDecryptedMainnet.toString());
428+
});
429+
430+
it('cannot be decrypted with an invalid transition view key', () => {
431+
expect(() => transitionMainnet.decryptTransition(invalidTransitionViewKey)).to.throw();
432+
});
433+
434+
it('can generate a transition view key from a valid view key', () => {
435+
const generatedTransitionViewKey = transitionMainnet.tvk(viewKey);
436+
437+
// Ensure the generated transition view key is the same as the one used to decrypt
438+
expect(generatedTransitionViewKey.toString()).equal(transitionViewKeyStringMainnet);
439+
});
440+
}
441+
});
442+
412443

413444
describe('EncryptionToolkit', () => {
414445
const recordCiphertextString = "record1qyqsqpe2szk2wwwq56akkwx586hkndl3r8vzdwve32lm7elvphh37rsyqyxx66trwfhkxun9v35hguerqqpqzqrtjzeu6vah9x2me2exkgege824sd8x2379scspmrmtvczs0d93qttl7y92ga0k0rsexu409hu3vlehe3yxjhmey3frh2z5pxm5cmxsv4un97q";

0 commit comments

Comments
 (0)