Skip to content

Commit

Permalink
Merge branch '113-ethereum-chain-fix-bugs' into 'dev'
Browse files Browse the repository at this point in the history
fix bugs in EVM packages

Closes #113

See merge request ergo/rosen-bridge/rosen-chains!133
  • Loading branch information
zargarzadehm committed Aug 15, 2024
2 parents a870083 + 63b0c22 commit 5aaf841
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-donkeys-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-chains/evm': major
---

add chain name and native token id to constructor to fix extractor intialization
5 changes: 5 additions & 0 deletions .changeset/cuddly-poems-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-chains/ethereum': patch
---

fix extractor initialization
5 changes: 5 additions & 0 deletions .changeset/eleven-mice-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-chains/evm': patch
---

fix tx serialization for rosen-extractor
5 changes: 5 additions & 0 deletions .changeset/lucky-eels-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-chains/evm-rpc': patch
---

fix transaction submission
1 change: 1 addition & 0 deletions package-lock.json

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

29 changes: 28 additions & 1 deletion packages/chains/ethereum/lib/EthereumChain.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
import { EvmChain } from '@rosen-chains/evm';
import {
AbstractEvmNetwork,
EvmChain,
EvmConfigs,
TssSignFunction,
} from '@rosen-chains/evm';
import { RosenTokens } from '@rosen-bridge/tokens';
import { AbstractLogger } from '@rosen-bridge/abstract-logger';
import { ETH, ETHEREUM_CHAIN } from './constants';

class EthereumChain extends EvmChain {
CHAIN = ETHEREUM_CHAIN;
NATIVE_TOKEN_ID = ETH;
CHAIN_ID = 1n;

constructor(
network: AbstractEvmNetwork,
configs: EvmConfigs,
tokens: RosenTokens,
supportedTokens: Array<string>,
signFunction: TssSignFunction,
logger?: AbstractLogger
) {
super(
network,
configs,
tokens,
supportedTokens,
signFunction,
ETHEREUM_CHAIN,
ETH,
logger
);
}
}

export default EthereumChain;
1 change: 1 addition & 0 deletions packages/chains/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@rosen-chains/evm": "^2.0.1"
},
"dependencies": {
"@rosen-bridge/abstract-logger": "^1.0.0",
"@rosen-bridge/tokens": "^1.2.1"
}
}
21 changes: 7 additions & 14 deletions packages/chains/evm/lib/EvmChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,21 @@ abstract class EvmChain extends AbstractChain<Transaction> {
tokens: RosenTokens,
supportedTokens: Array<string>,
signFunction: TssSignFunction,
CHAIN: string,
NATIVE_TOKEN_ID: string,
logger?: AbstractLogger
) {
super(network, configs, tokens, logger);
this.supportedTokens = supportedTokens;
this.signFunction = signFunction;
this.initExtractor(tokens, logger);
}

/**
* initializes rosen extractor
* @param tokens
* @param nativeToken
* @param logger
*/
protected initExtractor = (tokens: RosenTokens, logger?: any) => {
this.extractor = new EvmRosenExtractor(
this.configs.addresses.lock,
tokens,
this.CHAIN,
this.NATIVE_TOKEN_ID,
CHAIN,
NATIVE_TOKEN_ID,
logger
);
};
}

/**
* generates single or multiple unsigned PaymentTransactions for a payment order
Expand Down Expand Up @@ -773,7 +765,8 @@ abstract class EvmChain extends AbstractChain<Transaction> {
/**
* serializes the transaction of this chain into string
*/
protected serializeTx = (tx: Transaction): string => tx.toJSON();
protected serializeTx = (tx: Transaction): string =>
tx.serialized.substring(2);

/**
* gets the address balance for native token and all supported tokens
Expand Down
27 changes: 25 additions & 2 deletions packages/chains/evm/tests/EvmChain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { expect, vi } from 'vitest';
import TestEvmNetwork from './network/TestEvmNetwork';
import * as TestData from './testData';
import {
AssetNotSupportedError,
MaxParallelTxError,
Expand All @@ -10,17 +8,42 @@ import {
TransactionFormatError,
TransactionType,
} from '@rosen-chains/abstract-chain';
import TestEvmNetwork from './network/TestEvmNetwork';
import * as TestData from './testData';
import * as testUtils from './TestUtils';
import Serializer from '../lib/Serializer';
import { Transaction, TransactionLike } from 'ethers';
import { mockGetAddressBalanceForNativeToken } from './TestUtils';
import { EvmTxStatus } from '../lib';
import TestChain from './TestChain';

describe('EvmChain', () => {
const network = new TestEvmNetwork();

const evmChain = testUtils.generateChainObject(network);

describe(`constructor`, () => {
/**
* @target EvmChain.constructor should initialize rosen-extractor successfully
* @dependencies
* @scenario
* - initialize EvmChain
* - check CHAIN variable in rosen-extractor
* @expected
* - CHAIN variable should be the same as the one defined EvmChain
*/
it('should initialize rosen-extractor successfully', async () => {
const chain = new TestChain(
network,
testUtils.configs,
TestData.testTokenMap,
TestData.supportedTokens,
testUtils.mockedSignFn
);
expect(chain.extractor?.chain).toEqual(chain.CHAIN);
});
});

describe('generateMultipleTransactions', () => {
/**
* @target EvmChain.generateMultipleTransactions should generate payment transactions
Expand Down
11 changes: 9 additions & 2 deletions packages/chains/evm/tests/TestChain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { RosenTokens } from '@rosen-bridge/tokens';
import { AbstractEvmNetwork, EvmChain, TssSignFunction } from '../lib';
import { EvmRosenExtractor } from '@rosen-bridge/rosen-extractor';

class TestChain extends EvmChain {
CHAIN = 'test';
Expand All @@ -14,7 +13,15 @@ class TestChain extends EvmChain {
supportedTokens: Array<string>,
signFunction: TssSignFunction
) {
super(network, configs, tokens, supportedTokens, signFunction);
super(
network,
configs,
tokens,
supportedTokens,
signFunction,
'test',
'test-native-token'
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/networks/evm-rpc/lib/EvmRpcNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class EvmRpcNetwork extends AbstractEvmNetwork {
* @param transaction the transaction
*/
submitTransaction = async (transaction: Transaction): Promise<void> => {
await this.provider.broadcastTransaction(transaction.toJSON());
await this.provider.broadcastTransaction(transaction.serialized);
};

/**
Expand Down

0 comments on commit 5aaf841

Please sign in to comment.