Skip to content

Commit

Permalink
Merge branch '109-consider-transaction-failure-in-evmchain' into 'dev'
Browse files Browse the repository at this point in the history
consider transaction failure

Closes #109

See merge request ergo/rosen-bridge/rosen-chains!126
  • Loading branch information
vorujack committed Aug 4, 2024
2 parents 2a0a667 + 9729309 commit 87df5f6
Show file tree
Hide file tree
Showing 23 changed files with 535 additions and 76 deletions.
6 changes: 6 additions & 0 deletions .changeset/khaki-countries-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rosen-chains/evm-rpc': major
'@rosen-chains/evm': major
---

consider transaction failure
9 changes: 9 additions & 0 deletions .changeset/quick-parrots-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@rosen-chains/abstract-chain': major
'@rosen-chains/bitcoin': major
'@rosen-chains/cardano': major
'@rosen-chains/ergo': major
'@rosen-chains/evm': major
---

change `verifyLockTransactionExtraConditions` to async
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/abstract-chain/lib/AbstractChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ abstract class AbstractChain<TxType> {
`Failed in comparing event amount to fees: ${e}`
);
}
if (this.verifyLockTransactionExtraConditions(tx, blockInfo)) {
if (await this.verifyLockTransactionExtraConditions(tx, blockInfo)) {
this.logger.info(
`Event [${eventId}] has been successfully validated`
);
Expand Down Expand Up @@ -270,10 +270,10 @@ abstract class AbstractChain<TxType> {
* @param blockInfo
* @returns true if the transaction is verified
*/
verifyLockTransactionExtraConditions = (
verifyLockTransactionExtraConditions = async (
transaction: TxType,
blockInfo: BlockInfo
): boolean => {
): Promise<boolean> => {
throw Error(
`You must implement 'verifyLockTransactionExtraConditions' or override 'verifyEvent' implementation`
);
Expand Down
2 changes: 1 addition & 1 deletion packages/abstract-chain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@rosen-bridge/abstract-logger": "^1.0.0",
"@rosen-bridge/json-bigint": "^0.1.0",
"@rosen-bridge/minimum-fee": "^2.1.0",
"@rosen-bridge/rosen-extractor": "^6.0.1",
"@rosen-bridge/rosen-extractor": "^6.1.0",
"@rosen-bridge/tokens": "^1.2.1",
"blakejs": "^1.2.1"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/abstract-chain/tests/AbstractChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe('AbstractChain', () => {
chain,
'verifyLockTransactionExtraConditions'
);
verifyLockTxSpy.mockReturnValueOnce(true);
verifyLockTxSpy.mockResolvedValueOnce(true);

// run test
const result = await chain.verifyEvent(event, feeConfig);
Expand Down Expand Up @@ -517,7 +517,7 @@ describe('AbstractChain', () => {
chain,
'verifyLockTransactionExtraConditions'
);
verifyLockTxSpy.mockReturnValueOnce(true);
verifyLockTxSpy.mockResolvedValueOnce(true);

// run test
const result = await chain.verifyEvent(event, feeConfig);
Expand Down Expand Up @@ -597,7 +597,7 @@ describe('AbstractChain', () => {
chain,
'verifyLockTransactionExtraConditions'
);
verifyLockTxSpy.mockReturnValueOnce(true);
verifyLockTxSpy.mockResolvedValueOnce(true);

// run test
const result = await chain.verifyEvent(event, fee);
Expand Down Expand Up @@ -677,7 +677,7 @@ describe('AbstractChain', () => {
chain,
'verifyLockTransactionExtraConditions'
);
verifyLockTxSpy.mockReturnValueOnce(true);
verifyLockTxSpy.mockResolvedValueOnce(true);

// run test
const result = await chain.verifyEvent(event, fee);
Expand Down Expand Up @@ -746,7 +746,7 @@ describe('AbstractChain', () => {
chain,
'verifyLockTransactionExtraConditions'
);
verifyLockTxSpy.mockReturnValueOnce(false);
verifyLockTxSpy.mockResolvedValueOnce(false);

// run test
const result = await chain.verifyEvent(event, feeConfig);
Expand Down
4 changes: 2 additions & 2 deletions packages/chains/bitcoin/lib/BitcoinChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,10 @@ class BitcoinChain extends AbstractUtxoChain<BitcoinTx, BitcoinUtxo> {
* @param blockInfo
* @returns true if the transaction is verified
*/
verifyLockTransactionExtraConditions = (
verifyLockTransactionExtraConditions = async (
transaction: BitcoinTx,
blockInfo: BlockInfo
): boolean => {
): Promise<boolean> => {
return true;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/chains/bitcoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@rosen-bridge/abstract-logger": "^1.0.0",
"@rosen-bridge/bitcoin-utxo-selection": "^0.2.0",
"@rosen-bridge/json-bigint": "^0.1.0",
"@rosen-bridge/rosen-extractor": "^6.0.1",
"@rosen-bridge/rosen-extractor": "^6.1.0",
"@rosen-bridge/tokens": "^1.2.1",
"bitcoinjs-lib": "^6.1.5"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/chains/cardano/lib/CardanoChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,10 @@ class CardanoChain extends AbstractUtxoChain<CardanoTx, CardanoUtxo> {
* @param blockInfo
* @returns true if the transaction is verified
*/
verifyLockTransactionExtraConditions = (
verifyLockTransactionExtraConditions = async (
transaction: CardanoTx,
blockInfo: BlockInfo
): boolean => {
): Promise<boolean> => {
return true;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/chains/cardano/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@emurgo/cardano-serialization-lib-nodejs": "^11.3.1",
"@rosen-bridge/abstract-logger": "^1.0.0",
"@rosen-bridge/rosen-extractor": "^6.0.1",
"@rosen-bridge/rosen-extractor": "^6.1.0",
"@rosen-bridge/json-bigint": "^0.1.0",
"@rosen-bridge/tokens": "^1.2.1",
"bech32": "^2.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/chains/ergo/lib/ErgoChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ class ErgoChain extends AbstractUtxoChain<wasm.Transaction, wasm.ErgoBox> {
* @param blockInfo
* @returns true if the transaction is verified
*/
verifyLockTransactionExtraConditions = (
verifyLockTransactionExtraConditions = async (
transaction: wasm.Transaction,
blockInfo: BlockInfo
): boolean => {
): Promise<boolean> => {
const outputs = transaction.outputs();
for (let i = 0; i < outputs.len(); i++) {
const box = outputs.get(i);
Expand Down
2 changes: 1 addition & 1 deletion packages/chains/ergo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@rosen-bridge/abstract-logger": "^1.0.0",
"@rosen-bridge/json-bigint": "^0.1.0",
"@rosen-bridge/rosen-extractor": "^6.0.1",
"@rosen-bridge/rosen-extractor": "^6.1.0",
"@rosen-bridge/tokens": "^1.2.1",
"ergo-lib-wasm-nodejs": "^0.24.1"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/chains/ergo/tests/ErgoChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ describe('ErgoChain', () => {
* @expected
* - it should return false
*/
it('should return false when output box creation height is more than a year ago', () => {
it('should return false when output box creation height is more than a year ago', async () => {
const blockInfo: BlockInfo = {
hash: ergoTestUtils.generateRandomId(),
parentHash: ergoTestUtils.generateRandomId(),
Expand All @@ -1108,7 +1108,7 @@ describe('ErgoChain', () => {
);

const ergoChain = ergoTestUtils.generateChainObject(network);
const result = ergoChain.verifyLockTransactionExtraConditions(
const result = await ergoChain.verifyLockTransactionExtraConditions(
mockedTx,
blockInfo
);
Expand All @@ -1127,7 +1127,7 @@ describe('ErgoChain', () => {
* @expected
* - it should return true
*/
it('should return true when all output boxes creation heights are fresh', () => {
it('should return true when all output boxes creation heights are fresh', async () => {
const blockInfo: BlockInfo = {
hash: ergoTestUtils.generateRandomId(),
parentHash: ergoTestUtils.generateRandomId(),
Expand All @@ -1138,7 +1138,7 @@ describe('ErgoChain', () => {
);

const ergoChain = ergoTestUtils.generateChainObject(network);
const result = ergoChain.verifyLockTransactionExtraConditions(
const result = await ergoChain.verifyLockTransactionExtraConditions(
mockedTx,
blockInfo
);
Expand Down
Loading

0 comments on commit 87df5f6

Please sign in to comment.