Skip to content

Commit

Permalink
fix: fix out of order registers serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
capt-nemo429 committed Jan 9, 2023
1 parent b21a3ab commit 45321dd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/core/src/models/ergoBox.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
invalidBoxesMock,
manyTokensBoxesMock,
outOfOrderRegistersBox,
regularBoxesMock,
validBoxesMock
} from "../tests/mocks/mockBoxes";
Expand Down Expand Up @@ -36,6 +37,8 @@ describe("Validation", () => {
for (const box of validBoxesMock) {
expect(new ErgoBox(box).isValid()).toBeTruthy();
}

expect(new ErgoBox(outOfOrderRegistersBox).isValid()).toBeTruthy();
});

it("Should not validate invalid boxes", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/serializer/sigma/boxSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ function serializeTokens(tokens: TokenAmount<Amount>[]): Uint8Array {
}

function serializeRegisters(registers: NonMandatoryRegisters): Uint8Array {
const keys = Object.keys(registers);
let keys = Object.keys(registers);
if (isEmpty(keys)) {
return Uint8Array.from([0]);
}

const serializedRegisters: Uint8Array[] = [];
keys = keys.sort();
for (const key of keys) {
const val = registers[key as keyof NonMandatoryRegisters];
if (isDefined(val)) {
Expand Down
23 changes: 23 additions & 0 deletions packages/core/src/tests/mocks/mockBoxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1695,3 +1695,26 @@ export const invalidBoxesMock = [
}
}
];

export const outOfOrderRegistersBox = {
boxId: "d9ee4ee66b95f4676c74d7d9c9dca32010edb73cfe648a6ced1d678df981ca83",
value: "1100000000",
ergoTree:
"10190402040005000400040604000406050404000402040204000400040204000400040004020400040204040500010004000e208c7f0bebb3e09525094459c9081b78f5b8a3af995ecd46a1c8a34805c2650654d811d601db6903db6503fed602e4c6a70559d6038c720201d6049172017203d605e4c6a7040ed6068c720202d607db6308a7d608830002d609c1a7d60ab27207730001860272087209d60b8c720a02d60cc6a70611d60de4720cd60eb2720d730100d60fe4c6a7070ed61095ec8f720b720e948c720a01720f7302720bd611b2db6501fe730300ea02eb02ea02d17204cdeeb472057304b17205d1957204959172017206d802d612b2a5730500d613927210720eeced8f7210720e9683040193b1a5730693db63087212720792c172129972099c7307e4c67211060593c272127205ed72137213d806d612b2a5730800d613db63087212d614b2721373090186027208c17212d615e4c672110711d616b2a5730a00d617b2db63087216730b0186027208c1721696830c0193c5b2a4730c00c5a7938c721401720f928c721402a29a7210b2720d730d00720e93b27207730e00b27213730f0093c27212c2a793e4c67212040e720593e4c6721205598602720395909972067201b272157310009a7206b27215731100720693c672120611720c93e4c67212070e720f93b172139593b1720f73127313731493c27216e4c6a7080eeced938c721701720f928c721702721093721073157316d1938cb2db63087211731700017318",
assets: [
{
tokenId: "1ffa93059d1d3579de91c24d5246c6da0823703bd4a9aeff2b5f81fee71bf3e8",
amount: "1"
}
],
additionalRegisters: {
R5: "5980a5e8deb161c0c9d1aeb261",
R6: "110280a8d6b9078084af5f",
R4: "0e240008cd0333099ca68e2b307344ae521eb0f418c7affed0bf7f973c5a10886182345ce2e0",
R8: "0e240008cd0333099ca68e2b307344ae521eb0f418c7affed0bf7f973c5a10886182345ce2e0",
R7: "0e00"
},
creationHeight: 218333,
transactionId: "63661fccf4621fc9c9864f2cf5bb6a14ff7784156504101ac4199dd400196d82",
index: 0
};

0 comments on commit 45321dd

Please sign in to comment.