Skip to content

Commit

Permalink
Merge branch '74-update-eventtrigger-interface' into 'dev'
Browse files Browse the repository at this point in the history
Resolve "update EventTrigger interface"

Closes #74

See merge request ergo/rosen-bridge/rosen-chains!91
  • Loading branch information
zargarzadehm committed Feb 14, 2024
2 parents 8a6559c + ec38f7a commit a5793a1
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"baseBranch": "dev",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/rude-pumas-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-chains/abstract-chain': major
---

update event trigger type according to latest version of contracts
5 changes: 5 additions & 0 deletions .changeset/small-jokes-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-chains/ergo': major
---

change register type in generateTransaction function
3 changes: 2 additions & 1 deletion packages/abstract-chain/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ interface EventTrigger {
sourceTxId: string;
sourceChainHeight: number;
sourceBlockId: string;
WIDs: Array<string>;
WIDsHash: string;
WIDsCount: number;
}

enum SigningStatus {
Expand Down
18 changes: 6 additions & 12 deletions packages/chains/cardano/tests/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,8 @@ export const validEvent: EventTrigger = {
sourceChainHeight: 1000,
sourceBlockId:
'01a33c00accaa91ebe0c946bffe1ec294280a3a51a90f7f4b011f3f37c29c5ed',
WIDs: [
'6d9cfa68dbadb03b8c254db3b5b34da274d3ed039120143dbcf99cce0eaccc6c',
'9ec0d80a7c624bf5c0c5ef620f4b3d71e2b46a624a77d7a5571fab913b6d7b9c',
],
WIDsHash: 'bb2b2272816e1e9993fc535c0cf57c668f5cd39c67cfcd55b4422b1aa87cd0c3',
WIDsCount: 2,
};

export const invalidEvent: EventTrigger = {
Expand All @@ -382,10 +380,8 @@ export const invalidEvent: EventTrigger = {
sourceChainHeight: 1000,
sourceBlockId:
'01a33c00accaa91ebe0c946bffe1ec294280a3a51a90f7f4b011f3f37c29c5ed',
WIDs: [
'6d9cfa68dbadb03b8c254db3b5b34da274d3ed039120143dbcf99cce0eaccc6c',
'9ec0d80a7c624bf5c0c5ef620f4b3d71e2b46a624a77d7a5571fab913b6d7b9c',
],
WIDsHash: 'bb2b2272816e1e9993fc535c0cf57c668f5cd39c67cfcd55b4422b1aa87cd0c3',
WIDsCount: 2,
};

export const validEventWithHighFee: EventTrigger = {
Expand All @@ -404,10 +400,8 @@ export const validEventWithHighFee: EventTrigger = {
sourceChainHeight: 1000,
sourceBlockId:
'01a33c00accaa91ebe0c946bffe1ec294280a3a51a90f7f4b011f3f37c29c5ed',
WIDs: [
'6d9cfa68dbadb03b8c254db3b5b34da274d3ed039120143dbcf99cce0eaccc6c',
'9ec0d80a7c624bf5c0c5ef620f4b3d71e2b46a624a77d7a5571fab913b6d7b9c',
],
WIDsHash: 'bb2b2272816e1e9993fc535c0cf57c668f5cd39c67cfcd55b4422b1aa87cd0c3',
WIDsCount: 2,
};

export const cardanoTx1: CardanoTx = {
Expand Down
8 changes: 4 additions & 4 deletions packages/chains/ergo/lib/ErgoChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class ErgoChain extends AbstractUtxoChain<wasm.ErgoBox> {
if (order.extra !== undefined)
boxBuilder.set_register_value(
4,
wasm.Constant.from_coll_coll_byte([Buffer.from(order.extra, 'hex')])
wasm.Constant.from_byte_array(Buffer.from(order.extra, 'hex'))
);

// build and add box
Expand Down Expand Up @@ -380,7 +380,7 @@ class ErgoChain extends AbstractUtxoChain<wasm.ErgoBox> {
for (let i = 0; i < outputCandidatesLength; i++) {
const output = outputCandidates.get(i);
const assets = ErgoUtils.getBoxAssets(output);
const r4Value = output.register_value(4)?.to_coll_coll_byte()[0];
const r4Value = output.register_value(4)?.to_byte_array();

// skip change box and fee box
if (
Expand Down Expand Up @@ -804,7 +804,7 @@ class ErgoChain extends AbstractUtxoChain<wasm.ErgoBox> {
);

// extract wid
const wid = box.register_value(4)?.to_coll_coll_byte()[0];
const wid = box.register_value(4)?.to_byte_array();
if (wid === undefined) {
const boxId = box.box_id().to_str();
throw new Error(`failed to read WID from register R4 of box [${boxId}]`);
Expand Down Expand Up @@ -1027,7 +1027,7 @@ class ErgoChain extends AbstractUtxoChain<wasm.ErgoBox> {
continue;

const assets = ErgoUtils.getBoxAssets(output);
const r4Value = output.register_value(4)?.to_coll_coll_byte()[0];
const r4Value = output.register_value(4)?.to_byte_array();

const payment: SinglePayment = {
address: wasm.Address.recreate_from_ergo_tree(
Expand Down
7 changes: 4 additions & 3 deletions packages/chains/ergo/tests/ErgoChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as wasm from 'ergo-lib-wasm-nodejs';
import ErgoTransaction from '../lib/ErgoTransaction';
import { RosenData } from '@rosen-bridge/rosen-extractor';
import { Fee } from '@rosen-bridge/minimum-fee';
import JsonBigInt from '@rosen-bridge/json-bigint';

const spyOn = jest.spyOn;

Expand Down Expand Up @@ -2453,11 +2454,11 @@ describe('ErgoChain', () => {
// mock serialized transaction
const serializedTx = Buffer.from(
ergoTestUtils
.toTransaction(transactionTestData.transaction0)
.toTransaction(transactionTestData.transaction6)
.sigma_serialize_bytes()
).toString('hex');

const expectedOrder = transactionTestData.transaction0Order;
const expectedOrder = transactionTestData.transaction6Order;
const config: ErgoConfigs = {
fee: 1100000n,
confirmations: {
Expand All @@ -2467,7 +2468,7 @@ describe('ErgoChain', () => {
manual: manualTxConfirmation,
},
addresses: {
lock: 'nB3L2PD3LBtiNhDYK7XhZ8nVt6uekBXN7RcPUKgdKLXFcrJiSPxmQsUKuUkTRQ1hbvDrxEQAKYurGFbaGD1RPxU7XqQimD78j23HHMQKL1boUGsnNhCxaVNAYMcFbQNo355Af8cWkhAN6',
lock: '9hcBZ7khJGepr2ZXz4ZktxAa1bTmnRSmjTNb9vhsi2EwGprGE6Q',
cold: 'cold_addr',
permit: 'permit_addr',
fraud: 'fraud',
Expand Down
33 changes: 12 additions & 21 deletions packages/chains/ergo/tests/boxTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export const ergoBox1 = `{
}`;

export const ergoBox2 = `{
"boxId": "9ec54d613c9c4bea2824ba2d5126639e3c440dfbaa85af29c81288d6289fc47c",
"transactionId": "dd2f188a9177181fca5e864eb2f4e69febb91fa9bba409ecd8b075de895086fd",
"boxId": "ceea5d56155052be1be4f061b7daaef59c620466e1c9bb6cc5aeb5482fa1a4ed",
"transactionId": "047ed283de8cc9f470a4050a79a8989a44212a1eaa8dfe95a413ca8a98238190",
"blockId": "29ea82943b3304c4fdbc020345f31f79842496809e51ca22af9e0c9863fd486b",
"value": 300000,
"index": 2,
"index": 0,
"globalIndex": 28468851,
"creationHeight": 987236,
"settlementHeight": 987241,
Expand All @@ -65,9 +65,9 @@ export const ergoBox2 = `{
],
"additionalRegisters": {
"R4": {
"serializedValue": "1a012097a2dabcd974d69a07c3a03e20d05a36d13b986ffca5670302997484dd87e247",
"sigmaType": "Coll[Coll[SByte]]",
"renderedValue": "[97a2dabcd974d69a07c3a03e20d05a36d13b986ffca5670302997484dd87e247]"
"serializedValue": "0e2097a2dabcd974d69a07c3a03e20d05a36d13b986ffca5670302997484dd87e247",
"sigmaType": "Coll[SByte]",
"renderedValue": "97a2dabcd974d69a07c3a03e20d05a36d13b986ffca5670302997484dd87e247"
}
},
"spentTransactionId": "978793eabc97e6021bad9c68cc793c4f51bb829ddb08bee5f9127a9ed71a2701",
Expand Down Expand Up @@ -209,11 +209,8 @@ export const validEvent: EventTrigger = {
sourceChainHeight: 1000,
sourceBlockId:
'01a33c00accaa91ebe0c946bffe1ec294280a3a51a90f7f4b011f3f37c29c5ea',
WIDs: [
'6d9cfa68dbadb03b8c254db3b5b34da274d3ed039120143dbcf99cce0eaccc6e',
'9ec0d80a7c624bf5c0c5ef620f4b3d71e2b46a624a77d7a5571fab913b6d7b90',
'ebc091d854e83a8fdc0e51936923171fc74895715591be81b8d286888d877e70',
],
WIDsHash: '300a544b041a6f48c411c463d4c33c6fb650471d5ebd0332459b8855eeba14cd',
WIDsCount: 3,
};

export const validEventWithHighFee: EventTrigger = {
Expand All @@ -232,11 +229,8 @@ export const validEventWithHighFee: EventTrigger = {
sourceChainHeight: 1000,
sourceBlockId:
'01a33c00accaa91ebe0c946bffe1ec294280a3a51a90f7f4b011f3f37c29c5ea',
WIDs: [
'6d9cfa68dbadb03b8c254db3b5b34da274d3ed039120143dbcf99cce0eaccc6e',
'9ec0d80a7c624bf5c0c5ef620f4b3d71e2b46a624a77d7a5571fab913b6d7b90',
'ebc091d854e83a8fdc0e51936923171fc74895715591be81b8d286888d877e70',
],
WIDsHash: '300a544b041a6f48c411c463d4c33c6fb650471d5ebd0332459b8855eeba14cd',
WIDsCount: 3,
};

export const invalidEvent: EventTrigger = {
Expand All @@ -255,9 +249,6 @@ export const invalidEvent: EventTrigger = {
sourceChainHeight: 1000,
sourceBlockId:
'01a33c00accaa91ebe0c946bffe1ec294280a3a51a90f7f4b011f3f37c29c5ea',
WIDs: [
'6d9cfa68dbadb03b8c254db3b5b34da274d3ed039120143dbcf99cce0eaccc6e',
'9ec0d80a7c624bf5c0c5ef620f4b3d71e2b46a624a77d7a5571fab913b6d7b90',
'ebc091d854e83a8fdc0e51936923171fc74895715591be81b8d286888d877e70',
],
WIDsHash: '300a544b041a6f48c411c463d4c33c6fb650471d5ebd0332459b8855eeba14cd',
WIDsCount: 3,
};
98 changes: 96 additions & 2 deletions packages/chains/ergo/tests/transactionTestData.ts

Large diffs are not rendered by default.

0 comments on commit a5793a1

Please sign in to comment.