From 0ab7b7b7c3b1ae95e2902d220cbd2197cbcafaec Mon Sep 17 00:00:00 2001 From: mukeunkim Date: Fri, 24 Dec 2021 15:27:35 +0900 Subject: [PATCH] Apply Chain ID to hash functions. --- src/index.ts | 4 ++++ src/modules/common/Hash.ts | 42 +++++++++++++++++++++++++++++++++- tests/Amount.test.ts | 1 + tests/BOAClient.test.ts | 1 + tests/BitMask.test.ts | 1 + tests/Block.test.ts | 1 + tests/ECC.test.ts | 3 ++- tests/Hash.test.ts | 36 +++++++++++++++++++---------- tests/KeyPair.test.ts | 1 + tests/OpCode.test.ts | 1 + tests/Schnorr.test.ts | 1 + tests/Script.test.ts | 1 + tests/Serialize.test.ts | 1 + tests/Signature.test.ts | 3 ++- tests/Transaction.test.ts | 22 +++++++++--------- tests/TxBuilder.test.ts | 1 + tests/TxCanceller.test.ts | 1 + tests/TxPayloadFee.test.ts | 1 + tests/UTXOManager.test.ts | 1 + tests/Vote.test.ts | 7 +++--- tests/Votera.test.ts | 3 ++- tests/data/Blocks.sample3.json | 4 ++-- 22 files changed, 105 insertions(+), 32 deletions(-) diff --git a/src/index.ts b/src/index.ts index a0b61da5f..7c8da5654 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,11 @@ export { hashMulti, makeUTXOKey, hashFull, + hashFullNoMagic, hashPart, + setChainId, + getChainId, + ChainId, } from "./modules/common/Hash"; export { Height } from "./modules/common/Height"; export { KeyPair, PublicKey, SecretKey, VersionByte } from "./modules/common/KeyPair"; diff --git a/src/modules/common/Hash.ts b/src/modules/common/Hash.ts index e4d763783..a25ce4be9 100644 --- a/src/modules/common/Hash.ts +++ b/src/modules/common/Hash.ts @@ -249,6 +249,31 @@ export class VariableBytes { } } +/** + * A definition of various chain ID. + */ +export enum ChainId { + TestNet = 0, + CoinNet = 1, +} + +let g_chain_id: ChainId = ChainId.TestNet; + +/** + * Set Chain ID + * @param value The chain ID to be designated. + */ +export function setChainId(value: ChainId) { + g_chain_id = value; +} + +/** + * Returns the chain ID. + */ +export function getChainId(): ChainId { + return g_chain_id; +} + /** * Creates a hash and stores it in buffer. * @param source Original for creating hash @@ -266,6 +291,7 @@ export function hash(source: Buffer): Hash { */ export function hashMulti(...args: any[]): Hash { const buffer = new SmartBuffer(); + hashPart(JSBI.BigInt(g_chain_id), buffer); for (const m of args) hashPart(m, buffer); return new Hash(Buffer.from(SodiumHelper.sodium.crypto_generichash(Hash.Width, buffer.toBuffer()))); } @@ -286,16 +312,30 @@ export function makeUTXOKey(h: Hash, index: JSBI): Hash { * Calculates the hash of the buffer. * @param record The object to serialize for the hash for creation. * The object has a method named `computeHash`. + * @param use_chan_id If this value is true, the chain ID will be included in the hash. + * @param chain_id The chain ID * @returns The instance of the hash */ -export function hashFull(record: any): Hash { +export function hashFull(record: any, use_chan_id: boolean = true, chain_id: ChainId = g_chain_id): Hash { if (record === null || record === undefined) return Hash.Null; const buffer = new SmartBuffer(); + if (use_chan_id) hashPart(JSBI.BigInt(chain_id), buffer); hashPart(record, buffer); return hash(buffer.readBuffer()); } +/** + * Serializes all internal objects that the instance contains in a buffer. + * Calculates the hash of the buffer. + * @param record The object to serialize for the hash for creation. + * The object has a method named `computeHash`. + * @returns The instance of the hash + */ +export function hashFullNoMagic(record: any): Hash { + return hashFull(record, false); +} + /** * Serializes all internal objects that the instance contains in the buffer. * @param record The object to serialize for the hash for creation diff --git a/tests/Amount.test.ts b/tests/Amount.test.ts index 3d618772e..3c6a91fed 100644 --- a/tests/Amount.test.ts +++ b/tests/Amount.test.ts @@ -19,6 +19,7 @@ import assert from "assert"; describe("Test of Amount", () => { before("Wait for the package libsodium to finish loading", async () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); await sdk.SodiumHelper.init(); }); diff --git a/tests/BOAClient.test.ts b/tests/BOAClient.test.ts index 80689c9c8..f75141604 100644 --- a/tests/BOAClient.test.ts +++ b/tests/BOAClient.test.ts @@ -38,6 +38,7 @@ describe("BOA Client", () => { const agora_port: string = "2100"; before("Wait for the package libsodium to finish loading", async () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); await sdk.SodiumHelper.init(); }); diff --git a/tests/BitMask.test.ts b/tests/BitMask.test.ts index f232dce62..f508f7b15 100644 --- a/tests/BitMask.test.ts +++ b/tests/BitMask.test.ts @@ -20,6 +20,7 @@ import { SmartBuffer } from "smart-buffer"; describe("Test of BitMask", () => { before("Wait for the package libsodium to finish loading", async () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); await sdk.SodiumHelper.init(); }); diff --git a/tests/Block.test.ts b/tests/Block.test.ts index 88f96c640..f908e4f56 100644 --- a/tests/Block.test.ts +++ b/tests/Block.test.ts @@ -25,6 +25,7 @@ const samples: any[] = (() => { describe("Test of Block", () => { before("Wait for the package libsodium to finish loading", async () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); await sdk.SodiumHelper.init(); }); diff --git a/tests/ECC.test.ts b/tests/ECC.test.ts index a49702a2c..1e49bb5fe 100644 --- a/tests/ECC.test.ts +++ b/tests/ECC.test.ts @@ -19,6 +19,7 @@ import * as assert from "assert"; describe("Test of ECC", () => { before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); @@ -45,7 +46,7 @@ describe("Test of ECC", () => { it("Test of Scalar.fromHash", () => { const message = "BOSAGORA for the win"; const c = sdk.Scalar.fromHash(sdk.hashFull(message)); // challenge - assert.strictEqual(c.toString(false), "0x07c51164f99d03f143cfafdfb8638826b87f86c73b82180c33cfb11dbaba1df3"); + assert.strictEqual(c.toString(false), "0x023107b120bb7f00305c37cc9eab065bb956fd554b1b67060793f46f0d9b9c15"); }); it("Test of Scalar function", () => { diff --git a/tests/Hash.test.ts b/tests/Hash.test.ts index f7f373e18..086557824 100644 --- a/tests/Hash.test.ts +++ b/tests/Hash.test.ts @@ -65,13 +65,13 @@ describe("Hash", () => { // Check assert.strictEqual( h.toString(), - "0xe0343d063b14c52630563ec81b0f91a84ddb05f2cf05a2e4330ddc79bd3a06e57c2e756f276c112342ff1d6f1e74d05bdb9bf880abd74a2e512654e12d171a74" + "0xc8271ef13d23732fa4628f68325432a7df36b0deb0a089f536c7cf7eefe0615ee6598c9c790ebe14141d74546f49b2dd11171b0d39f4297db25af72ea024a250" ); // Source 3 : "boa" const boa = sdk.hash(Buffer.from("boa")); - const h2 = sdk.hash(Buffer.concat([foo.data, bar.data, boa.data])); + const h2 = sdk.hash(Buffer.concat([Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]), foo.data, bar.data, boa.data])); const h3 = sdk.hashMulti(foo, bar, boa); // Check @@ -131,7 +131,7 @@ describe("Hash", () => { // Check assert.strictEqual( key.toString(), - "0x4c4e169e6619207b6613496c777b21431c5e14a29c44b316a55c8132416823bf9d202b8335d4c90810783e139ac0795b9a58993bf4bd10d1bc0b1a131fd09c64" + "0xebf52984772aed2ad1bf97252e7f204f7607182cbf55c7d7a3bbf6649fb3a7ee79a7810ce31c831da830a6c7f6c84c4129f14d1e93a9b5afe3b91fd2aaf9c6de" ); }); @@ -143,19 +143,19 @@ describe("Hash", () => { // UInt8 assert.strictEqual( sdk.hashMulti(foo, sdk.VariableBytes.fromUInt8(45)).toString(), - "0xf61564563b39715729ced8bff16b50b622d3ae38bc41f40d2f131961cf68ad8b931906921ff40e9e024fae067bea3bc48a86be5729713952b64d1f15b03a9f62" + "0x4302de357edbf92bbc7ab1fa6c0725c882e9fdc7cbf1a7647b72e46355ebbbec72e90eaeb8378ce536d4da84bef86ed44baf942d94e52b2f289edde7ff0d3fef" ); // UInt16 assert.strictEqual( sdk.hashMulti(foo, sdk.VariableBytes.fromUInt16(45)).toString(), - "0x605ca7649eda97e108ade8f1c390ad109dd39ac3824369c31a9647d234dafda65d8159ec5f9f7808052abed8e95bc9d86fc7f612632a156b81b4082aa2da4435" + "0x85be6919b5276738562c070c635f51af884589f9a65d9d2fa179e38d5fc31a6d1fc3a9a337c085565d91319f8b01f89751aa1b9efafc570964a30d5d87cc5644" ); // UInt32 assert.strictEqual( sdk.hashMulti(foo, sdk.VariableBytes.fromUInt32(45)).toString(), - "0xfd36a5e3a160b516c459a0ab08f65e352bd63b1ec3ceea393a04d7009b3c301c150057ca5a6363607c7c0cc37bffba853c3351ed6b953e7c947e82c810f453b9" + "0xa8fe8e8d0a416d96e56226ef22b8ae1eef5487cf057dbb82e4ba16f60e9dacd058a364721266d5f9cdae6f9f9166f8f44357efb347783ae77576c01332459fa9" ); }); @@ -167,7 +167,7 @@ describe("Hash", () => { const hash = sdk.makeUTXOKey(tx_hash, sdk.JSBI.BigInt(1)); assert.strictEqual( hash.toString(), - "0x7c95c29b184e47fbd32e58e5abd42c6e22e8bd5a7e934ab049d21df545e09c2e33bb2b89df2e59ee01eb2519b1508284b577f66a76d42546b65a6813e592bb84" + "0x35f0a7e120738d87431507d168a44c9b16b0381d0c6d7a62b5eb6ec5070fcfc46ebf753a8da5623cef1a2a80e03174cbd63be0ed3143311a1e19524940460c14" ); }); @@ -188,7 +188,7 @@ describe("Hash", () => { ); assert.strictEqual( sdk.hashFull(header).toString(), - "0xbcf8118c75dfab48ef62235a2908aa4a659feee8cee513dd3329b7eee5a4feab16c4802abb819b884fc2e845c65ecc348f1b5d1f5de7350b24fc08fc6c702107" + "0x08e3eac0394512060fb6d47a28092888c9b100149ab0c925d36ba554c90d8ebee0269789bb0f6d03117b43117a05ecc24849f0a6020dd7bce0a66065379eb9a3" ); }); @@ -213,7 +213,7 @@ describe("Hash", () => { ); assert.strictEqual( sdk.hashFull(header).toString(), - "0xabb03b214d7568274253e1a95c3f928165b8fb643249a2eaf9f7c19b2f9041a9666bf8a2961f9c56f25fe8a5f6c780ead8651cee5c412f53849086c062dda964" + "0x9df8acdbece16d9f690fb6c81bd65b5ff5840619a79fc357b6a4667211a73add8915e557950281d95612eb875a9d490583fb8190fabe893279716bfc440b0e3d" ); }); @@ -222,7 +222,7 @@ describe("Hash", () => { const scalar = new sdk.Scalar("0x0e00a8df701806cb4deac9bb09cc85b097ee713e055b9d2bf1daf668b3f63778"); assert.deepStrictEqual( sdk.hashFull(scalar).toString(), - "0x4f895cc641b2bfe4541f53b83445add00a7a81ad340312c51cbf15c53ddebcc7ea7dcd11a97e085d28552026952e7c7c8d4276d5901d33605a3ea21027a673d4" + "0x0528f5a8f7d6298e6f560d05283e6256911cbb6ffb18eee5a3a9e8f423ec468cb49a89d6f78fac459668ed819610d6e6b323391675271243f9fbf7036a4512fe" ); }); @@ -231,7 +231,7 @@ describe("Hash", () => { const point = new sdk.Point("0xdb445140a72012a177535f43e6bbb8523ff21de465a7c35b42be1a447e5e2908"); assert.deepStrictEqual( sdk.hashFull(point).toString(), - "0xa0ad987cffcf2e3f96af64dd197d95d4e8e41be4448f6abebd8953b3c37b3132a1a1917c2046f6d3550cac70299110b28f23454d6124892ab2b8a6508f2bfe47" + "0x2358dd06aeca72e8bcb5918f1c4abae9eee8174e5af68e02b17d3c035b459663baee8c0cf6f7e4a1a7944d2494243a69d6f6db182071ddc25b5b5a7c7e42a635" ); }); @@ -240,7 +240,19 @@ describe("Hash", () => { const publicKey = new sdk.PublicKey("boa1xrr66q4rthn4qvhhsl4y5hptqm366pgarqpk26wfzh6d38wg076tsqqesgg"); assert.deepStrictEqual( sdk.hashFull(publicKey).toString(), - "0x774d28bb3dc06a1418a4165109f4e8e4e05b4b283c798dd10aa70050a9b095408b3d1c6c1017b69912e94a4a58c5cb522e78b9741e1380bb5d2d705116f886ef" + "0xd7935c2af683f3b28f2040ca41e3d5ee352b30237f1aabba85d09c01262e88b84ae8f37057a33f4bb14968dd97e86119f436a7a7ebe2fd1be0ce9eeb888a02ad" ); }); + + it("Test of ChainId", () => { + const secret: sdk.JSBI = sdk.JSBI.BigInt(0x1337); + assert.notDeepStrictEqual(sdk.hashFull(secret, true, 0xdead), sdk.hashFull(secret, true, 0xbeef)); + assert.notDeepStrictEqual(sdk.hashFull(secret, true, 0xdead), sdk.hashFullNoMagic(secret)); + const secret2: sdk.JSBI = sdk.JSBI.BigInt(0x0f0f); + const multi_hash = sdk.hashMulti(secret, secret2); + + sdk.setChainId(0xdead); + assert.deepStrictEqual(sdk.hashFull(secret, true, 0xdead), sdk.hashFull(secret)); + assert.notDeepStrictEqual(multi_hash, sdk.hashMulti(secret, secret2)); + }); }); diff --git a/tests/KeyPair.test.ts b/tests/KeyPair.test.ts index 3dadef34d..06dc5d3f3 100644 --- a/tests/KeyPair.test.ts +++ b/tests/KeyPair.test.ts @@ -21,6 +21,7 @@ import { bech32, bech32m } from "bech32"; describe("Public Key", () => { before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); diff --git a/tests/OpCode.test.ts b/tests/OpCode.test.ts index ff85448ca..fc0029489 100644 --- a/tests/OpCode.test.ts +++ b/tests/OpCode.test.ts @@ -19,6 +19,7 @@ import * as assert from "assert"; describe("Test OPCode", () => { before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); diff --git a/tests/Schnorr.test.ts b/tests/Schnorr.test.ts index 69026b0a3..b0fdc0bf0 100644 --- a/tests/Schnorr.test.ts +++ b/tests/Schnorr.test.ts @@ -19,6 +19,7 @@ import * as assert from "assert"; describe("Test of Schnorr", () => { before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); diff --git a/tests/Script.test.ts b/tests/Script.test.ts index 547483179..52b93d287 100644 --- a/tests/Script.test.ts +++ b/tests/Script.test.ts @@ -19,6 +19,7 @@ import * as assert from "assert"; describe("Test Script", () => { before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); diff --git a/tests/Serialize.test.ts b/tests/Serialize.test.ts index 29620cd4a..cfb3bd695 100644 --- a/tests/Serialize.test.ts +++ b/tests/Serialize.test.ts @@ -256,6 +256,7 @@ describe("Serialize and Deserialize", () => { }; before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); diff --git a/tests/Signature.test.ts b/tests/Signature.test.ts index f79f3432c..d1f628204 100644 --- a/tests/Signature.test.ts +++ b/tests/Signature.test.ts @@ -21,6 +21,7 @@ import { Hash } from "../src"; describe("Signature", () => { let sample_tx: sdk.Transaction; before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); @@ -63,7 +64,7 @@ describe("Signature", () => { it("Test for hash value of transaction data", () => { assert.strictEqual( sdk.hashFull(sample_tx).toString(), - "0xbf16b1bb63c50170ce0e2624e13bda540c268c74a677d2d8a0571eb79cd8a3b28c408793d43e3bbee0ffd39913903c77fbd1b0cbe36b6a0b503514bbbe84b492" + "0xadbc0332bd71d64d134e77f3c1e1828b1b4543f4922dc93bd6c3eff1c1c29f33f9cdb3980b1a6dddd6ac483b7766c8e21a3334f48eac39bec18802637e457a2f" ); const seed = `SDV3GLVZ6W7R7UFB2EMMY4BBFJWNCQB5FTCXUMD5ZCFTDEVZZ3RQ2BZI`; const kp = sdk.KeyPair.fromSeed(new sdk.SecretKey(seed)); diff --git a/tests/Transaction.test.ts b/tests/Transaction.test.ts index da2f26b7c..ba6e2890a 100644 --- a/tests/Transaction.test.ts +++ b/tests/Transaction.test.ts @@ -19,6 +19,7 @@ import * as assert from "assert"; describe("Transaction", () => { before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); @@ -32,7 +33,7 @@ describe("Transaction", () => { ); assert.strictEqual( sdk.hashFull(payment_tx).toString(), - "0xbf16b1bb63c50170ce0e2624e13bda540c268c74a677d2d8a0571eb79cd8a3b28c408793d43e3bbee0ffd39913903c77fbd1b0cbe36b6a0b503514bbbe84b492" + "0xadbc0332bd71d64d134e77f3c1e1828b1b4543f4922dc93bd6c3eff1c1c29f33f9cdb3980b1a6dddd6ac483b7766c8e21a3334f48eac39bec18802637e457a2f" ); assert.ok(payment_tx.isPayment()); @@ -47,7 +48,7 @@ describe("Transaction", () => { assert.strictEqual( sdk.hashFull(freeze_tx).toString(), - "0x415e67be1be0ae5d93c39198682e7202047e884542fbb1f88360895ad98195067f59f21a1bf8a57f364aaaed7ba8ce9196927a81262db5df0912ac0bf068307e" + "0x7958451244fd136328f75514ebb54eda51320b36835ed024582abc2238baf40d3edf813dd7fc8d9b2b1c89c015f89d09ccc2cd73de58512a7202fe850c0eed0d" ); assert.ok(!freeze_tx.isPayment()); @@ -61,7 +62,7 @@ describe("Transaction", () => { ); assert.strictEqual( sdk.hashFull(payload_tx).toString(), - "0x44590847e54f0e67c3365540115204df7730ddde5fdef306c5fd66af6a7d6f311f65de5058ce3f297f8e665a6c2b6d75a39207075a45b364a5dfba74fecf7547" + "0x4c8f4f2b1516d94cee686547d279c617a35734f11f4cb3d90bd9c1325a91c68a6146dc7018ff27368e6e07126a82f991a52aad40a04ac01b0a57605e14f55e4b" ); }); @@ -84,8 +85,7 @@ describe("Transaction", () => { ); assert.strictEqual( sdk.hashFull(tx1).toString(), - "0x8ae9a3478433a8602e6f75aabbc2c7bcb3d17afb0ef7e5b5645cbadb68021d1" + - "947d2a57020d45b79c8834e92eb04976b972ef542a589790fa593e33dc341f07b" + "0x2db765b318d83e32c70fbc2b0daa5a56158b089da0be4e8477cab6b9c3d460b5c382f8c16af834284f4a06c4a416550be6a707fe0544cbd261c59a11b991915d" ); const tx2 = new sdk.Transaction( @@ -106,7 +106,7 @@ describe("Transaction", () => { ); assert.strictEqual( sdk.hashFull(tx2).toString(), - "0x8ae9a3478433a8602e6f75aabbc2c7bcb3d17afb0ef7e5b5645cbadb68021d1947d2a57020d45b79c8834e92eb04976b972ef542a589790fa593e33dc341f07b" + "0x2db765b318d83e32c70fbc2b0daa5a56158b089da0be4e8477cab6b9c3d460b5c382f8c16af834284f4a06c4a416550be6a707fe0544cbd261c59a11b991915d" ); }); @@ -133,7 +133,7 @@ describe("Transaction", () => { ); assert.strictEqual( sdk.hashFull(tx1).toString(), - "0x559613a7a8d5e15275312256ba3205333e038a23f07c4c2bd0ef193c16cac114bd72f02183731c51132e9ee9471a1ae9495a84f86837d8917792fee9db713877" + "0xf5f72ceb5d5b19f3d6a54649ec25dd8f331881d19056631a92449da13f566da70bba365e3a351e849a0f8a6012f31f31ca212570a9cef10a25e0e4f57343956f" ); const tx2 = new sdk.Transaction( @@ -158,7 +158,7 @@ describe("Transaction", () => { ); assert.strictEqual( sdk.hashFull(tx2).toString(), - "0x559613a7a8d5e15275312256ba3205333e038a23f07c4c2bd0ef193c16cac114bd72f02183731c51132e9ee9471a1ae9495a84f86837d8917792fee9db713877" + "0xf5f72ceb5d5b19f3d6a54649ec25dd8f331881d19056631a92449da13f566da70bba365e3a351e849a0f8a6012f31f31ca212570a9cef10a25e0e4f57343956f" ); }); @@ -185,7 +185,7 @@ describe("Transaction", () => { ); assert.strictEqual( sdk.hashFull(tx1).toString(), - "0xf7930aeb05490a1a3cf42bb87f1ef22685dde78bb3554c4f46da2c69f47d584cac620a3f4d482d605c7917918c18bf30b4b3a542efcaa16a22b5582022c6b2b7" + "0x048418fe03f13fb0094ec50252d4aa530fbeb4929d09763a35fbb8d17fe3ee8d370a6b5d5ceb1f2e85f77175bd43f7dc409133fd4500d56b77de4d481730f771" ); const tx2 = new sdk.Transaction( @@ -210,7 +210,7 @@ describe("Transaction", () => { ); assert.strictEqual( sdk.hashFull(tx2).toString(), - "0xf7930aeb05490a1a3cf42bb87f1ef22685dde78bb3554c4f46da2c69f47d584cac620a3f4d482d605c7917918c18bf30b4b3a542efcaa16a22b5582022c6b2b7" + "0x048418fe03f13fb0094ec50252d4aa530fbeb4929d09763a35fbb8d17fe3ee8d370a6b5d5ceb1f2e85f77175bd43f7dc409133fd4500d56b77de4d481730f771" ); }); @@ -260,7 +260,7 @@ describe("Transaction", () => { ); assert.deepStrictEqual( tx.getChallenge().toString(), - "0xcea9497ef31f10007215455d20b25d3857100fb07395a4dea9015465a3d916bd82a3ab3fadce98673f1ca913f50e49460d88c2f704ebb2badc435af5699e3b80" + "0x4a150c933fb180f64491cdcc31bba89cf30363c93d67ac79e098a7ef265303b06c2909781d20396dcb1e1f370633ec3fbc027c4a540b115eef0b5709afe6cc4e" ); }); diff --git a/tests/TxBuilder.test.ts b/tests/TxBuilder.test.ts index 4d2b77bcd..ccb00bd45 100644 --- a/tests/TxBuilder.test.ts +++ b/tests/TxBuilder.test.ts @@ -23,6 +23,7 @@ describe("TxBuilder", () => { let owner: sdk.KeyPair; before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); diff --git a/tests/TxCanceller.test.ts b/tests/TxCanceller.test.ts index 26ec56e3c..4dc47e88a 100644 --- a/tests/TxCanceller.test.ts +++ b/tests/TxCanceller.test.ts @@ -56,6 +56,7 @@ describe("TxCanceller", () => { } before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); diff --git a/tests/TxPayloadFee.test.ts b/tests/TxPayloadFee.test.ts index 185a37586..dad1c0de4 100644 --- a/tests/TxPayloadFee.test.ts +++ b/tests/TxPayloadFee.test.ts @@ -19,6 +19,7 @@ import * as assert from "assert"; describe("TxPayloadFee", () => { before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); diff --git a/tests/UTXOManager.test.ts b/tests/UTXOManager.test.ts index a2d16f025..9ac8ef35f 100644 --- a/tests/UTXOManager.test.ts +++ b/tests/UTXOManager.test.ts @@ -22,6 +22,7 @@ describe("Test for UTXOManager", () => { let utxos: sdk.UnspentTxOutput[]; before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); diff --git a/tests/Vote.test.ts b/tests/Vote.test.ts index 07f5d6c8e..1d3d8eea9 100644 --- a/tests/Vote.test.ts +++ b/tests/Vote.test.ts @@ -20,6 +20,7 @@ import { SmartBuffer } from "smart-buffer"; describe("Vote Data", () => { before("Wait for the package libsodium to finish loading", () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); return sdk.SodiumHelper.init(); }); @@ -64,7 +65,7 @@ describe("Vote Data", () => { ); assert.deepStrictEqual( sdk.hashFull(voter_card).toString(), - "0x4c06291fc7384fd760c562a35f637c87f6333153416ef6da4e0b547dcabedc411350b5281286780b95d9dcb6496ea90622283508ea3e7b06a13ea2d909c09e91" + "0x127ca0d5e8227c566fef7e48f6f725538dd21d740841889b97fe1eed86378254f003e670fa0e63836b2c6afffaf58fa15a839552328558df9658d8cc2a8ef395" ); }); @@ -119,7 +120,7 @@ describe("Vote Data", () => { assert.ok(keypair.address.verify(encryption_key.signature, encryption_key)); const signature_agora = new sdk.Signature( - "0x5f3445d7788815ecabd181d6cea1f4ab501f196e5375e1359e12975c1081c88605012fdaa85754202b9bb83c8bc27ba1c1657dd0dc316b78ebe04aaed1dab7f3" + "0xf2c9ea243095bcc8873df56b1385b1603bdd18877bde9c825cc9213e5d2803ec035b9708839bf2fd65c8284b13497a0d5e88033b456f84243615f24243179bb3" ); assert.ok(keypair.address.verify(signature_agora, encryption_key)); }); @@ -269,7 +270,7 @@ describe("Vote Data", () => { const link_data = ballot_data.getLinkData(); const expected = { payload: - "CEJBTExPVCAgBlZvdGVyYQxJRDEyMzQ1Njc4OTApadJyWsl6W0jtPSAbVd/480x8QP4w75B04GJ1PctWghJ0SFXQBu/6DdPFrSKdkwbnyCSISJw+l76oyJmY8Vncx0mYjWFV1big5setAqNd51Ay94fqSlwrBuOtBR0YA2VpyRX02J3If7S4FDIwMjEtMDQtMTVUMDA6MDA6MDBa9i0ApJ9uClkCpExqGNYxlCL/l3xvcKNrG883y6C8Jg/a37ck9+mAFwPYHZt8nIaPialBd+7hiGiQ9TGDOX99s2Q9y7mHo7hjXUxVCb5G7dKxPe0D47FCOQXVBaQ9xJ8OC20P62WjgBZy3vNHxvh9Fx4vxkMEjA2mw8Iq6Ajr6YJd", + "CEJBTExPVCAgBlZvdGVyYQxJRDEyMzQ1Njc4OTApJYEySUD5nLZsgi2nA0jtrMx9mzujQpSmW1NsxI2yFEvqv7b4GydsZELFrSKdkwbnyCSISJw+l76oyJmY8Vncx0mYjWFV1big5setAqNd51Ay94fqSlwrBuOtBR0YA2VpyRX02J3If7S4FDIwMjEtMDQtMTVUMDA6MDA6MDBa6wswf3ZlMmQ28ne1fOI/rccq85FNsVh9p8SafJHc0QDGntZQvGmxqgrf7NhNTT42CAshcy8ZQndbIgWsJGlDw2RYYc8CIBkRsgCwM6ZG7Aq6GrHP/nEnrYKhXlBMM7HSCUy7XnYG4pt/Hbh2uVqkYE5HU85YrIiGYwP7woJA7Av3", }; const deserialized_ballot_data = sdk.BallotData.deserialize( diff --git a/tests/Votera.test.ts b/tests/Votera.test.ts index 321497eb9..b4b5f05b6 100644 --- a/tests/Votera.test.ts +++ b/tests/Votera.test.ts @@ -245,7 +245,7 @@ export class TestStoa { ), ], Buffer.from( - "CEJBTExPVCAgBlZvdGVyYQxJRDEyMzQ1Njc4OTApadJyWsl6W0jtPSAbVd/480x8QP4w75B04GJ1PctWghJ0SFXQBu/6DdPFrSKdkwbnyCSISJw+l76oyJmY8Vncx0mYjWFV1big5setAqNd51Ay94fqSlwrBuOtBR0YA2VpyRX02J3If7S4FDIwMjEtMDQtMTVUMDA6MDA6MDBa9i0ApJ9uClkCpExqGNYxlCL/l3xvcKNrG883y6C8Jg/a37ck9+mAFwPYHZt8nIaPialBd+7hiGiQ9TGDOX99s2Q9y7mHo7hjXUxVCb5G7dKxPe0D47FCOQXVBaQ9xJ8OC20P62WjgBZy3vNHxvh9Fx4vxkMEjA2mw8Iq6Ajr6YJd", + "CEJBTExPVCAgBlZvdGVyYQxJRDEyMzQ1Njc4OTApJYEySUD5nLZsgi2nA0jtrMx9mzujQpSmW1NsxI2yFEvqv7b4GydsZELFrSKdkwbnyCSISJw+l76oyJmY8Vncx0mYjWFV1big5setAqNd51Ay94fqSlwrBuOtBR0YA2VpyRX02J3If7S4FDIwMjEtMDQtMTVUMDA6MDA6MDBa6wswf3ZlMmQ28ne1fOI/rccq85FNsVh9p8SafJHc0QDGntZQvGmxqgrf7NhNTT42CAshcy8ZQndbIgWsJGlDw2RYYc8CIBkRsgCwM6ZG7Aq6GrHP/nEnrYKhXlBMM7HSCUy7XnYG4pt/Hbh2uVqkYE5HU85YrIiGYwP7woJA7Av3", "base64" ) ); @@ -352,6 +352,7 @@ describe("Checking the proposal and ballot data", () => { const agora_port: string = "3210"; before("Wait for the package libsodium to finish loading", async () => { + sdk.setChainId(sdk.ChainId.TestNet); if (!sdk.SodiumHelper.isAssigned()) sdk.SodiumHelper.assign(new BOASodium()); await sdk.SodiumHelper.init(); }); diff --git a/tests/data/Blocks.sample3.json b/tests/data/Blocks.sample3.json index 01219b674..cae5bb8ee 100644 --- a/tests/data/Blocks.sample3.json +++ b/tests/data/Blocks.sample3.json @@ -182,7 +182,7 @@ }, { "header": { - "prev_block": "0x6db06ab1cae5c4b05e806401e2c42d526ebf4ac81411d0fcd82344561b5a25ae0d29728f5c1c9bec6cf254f621c183be71858a6ed5339c06fc5b34d7881b9b23", + "prev_block": "0x5cee92785436c86ff542d84ab001bfeb7ef248a84102f66749f39bda31322e96b619c90c904e877c3542a7634aec0b1f5e647005160201a7126ea1f371b9fa82", "merkle_root": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "signature": "0xadb6fa02d8a83d7a580c012aafb025fb2e4fc5e4789f02f0e72468f6839f9b9f04bdbb61771c5ac1d21655714e53562488beeedeed747c2252e6851cb9beb7da", "validators": "110111", @@ -208,7 +208,7 @@ }, { "header": { - "prev_block": "0x0834e2207a3d4ed20bec5d61084e372139965d494002509618a2738e5553d9f559faf29d3b6f5c35fb3436019e8f3a1c4927dc23a49d6b33f95efacd9ead62dc", + "prev_block": "0x33380f05eae66cb1a8ebd038fd683ccb922e66a5709665eb0d3af62cd801477d99f62b0dc5684a7f794de7127d4b181fc31144067cb487fb4d1c177a6a7b6752", "merkle_root": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "signature": "0x46f9ee0dc9340df24278fae2802a18d5290bad4f9c193ddadd70d2c6658c5822096566170baef443e5ecabe1c387ad9b1c916d8f106228a927dbaaefc1eb7ce9", "validators": "11111",