diff --git a/packages/common/README.md b/packages/common/README.md index 1124468ef7..b57ce59280 100644 --- a/packages/common/README.md +++ b/packages/common/README.md @@ -257,6 +257,7 @@ The following custom chains are currently supported: - `PolygonMainnet` - `PolygonMumbai` +- `PolygonAmoy` - `ArbitrumRinkebyTestnet` - `xDaiChain` - `OptimisticKovan` diff --git a/packages/common/docs/enums/CustomChain.md b/packages/common/docs/enums/CustomChain.md index 01d4fbd548..d16abffd5f 100644 --- a/packages/common/docs/enums/CustomChain.md +++ b/packages/common/docs/enums/CustomChain.md @@ -11,6 +11,7 @@ - [OptimisticKovan](CustomChain.md#optimistickovan) - [PolygonMainnet](CustomChain.md#polygonmainnet) - [PolygonMumbai](CustomChain.md#polygonmumbai) +- [PolygonAmoy](CustomChain.md#polygonamoy) - [xDaiChain](CustomChain.md#xdaichain) ## Enumeration Members @@ -84,6 +85,20 @@ Polygon (Matic) Mumbai Testnet [enums.ts:101](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common/src/enums.ts#L101) ___ +### PolygonAmoy + +• **PolygonAmoy** = ``"polygon-amoy"`` + +Polygon (Matic) Amoy Testnet + +- [Block Explorer](https://amoy.polygonscan.com/) + +#### Defined in + +[enums.ts:137](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common/src/enums.ts#L137) + +___ + ### xDaiChain diff --git a/packages/common/src/common.ts b/packages/common/src/common.ts index 1ee56627c7..e5aa355f10 100644 --- a/packages/common/src/common.ts +++ b/packages/common/src/common.ts @@ -129,6 +129,16 @@ export class Common { opts ) } + if (chainParamsOrName === CustomChain.PolygonAmoy) { + return Common.custom( + { + name: CustomChain.PolygonAmoy, + chainId: 80002, + networkId: 80002, + }, + opts + ) + } if (chainParamsOrName === CustomChain.ArbitrumOne) { return Common.custom( { diff --git a/packages/common/src/enums.ts b/packages/common/src/enums.ts index 2c2f9553b2..3b6645e95b 100644 --- a/packages/common/src/enums.ts +++ b/packages/common/src/enums.ts @@ -128,4 +128,11 @@ export enum CustomChain { * - [Documentation](https://community.optimism.io/docs/developers/tutorials.html) */ OptimisticEthereum = 'optimistic-ethereum', + + /** + * Polygon (Matic) Amoy Testnet + * + * - [Block Explorer](https://amoy.polygonscan.com/) + */ + PolygonAmoy = 'polygon-amoy', } diff --git a/packages/common/test/customChains.spec.ts b/packages/common/test/customChains.spec.ts index e0fedf7990..becbb12342 100644 --- a/packages/common/test/customChains.spec.ts +++ b/packages/common/test/customChains.spec.ts @@ -98,6 +98,52 @@ describe('[Common]: Custom chains', () => { } }) + it('custom() -> behavior', () => { + let common = Common.custom({ chainId: 123 }) + assert.deepEqual(common.networkId(), BigInt(1), 'should default to mainnet base chain') + assert.equal(common.chainName(), 'custom-chain', 'should set default custom chain name') + + common = Common.custom(CustomChain.PolygonAmoy) + assert.deepEqual( + common.networkId(), + BigInt(80002), + 'supported chain -> should initialize with correct chain ID' + ) + for (const customChain of Object.values(CustomChain)) { + common = Common.custom(customChain) + assert.equal( + common.chainName(), + customChain, + `supported chain -> should initialize with enum name (${customChain})` + ) + } + + common = Common.custom(CustomChain.PolygonAmoy) + assert.equal( + common.hardfork(), + common.DEFAULT_HARDFORK, + 'uses default hardfork when no options are present' + ) + + common = Common.custom(CustomChain.OptimisticEthereum, { hardfork: Hardfork.Byzantium }) + assert.equal( + common.hardfork(), + Hardfork.Byzantium, + 'should correctly set an option (default options present)' + ) + + try { + //@ts-ignore TypeScript complains, nevertheless do the test for JS behavior + Common.custom('this-chain-is-not-supported') + assert.fail('test should fail') + } catch (e: any) { + assert.ok( + e.message.includes('not supported'), + 'supported chain -> should throw if chain name is not supported' + ) + } + }) + it('customChains parameter: initialization exception', () => { try { new Common({ chain: testnet, customChains: [testnet] as ChainConfig[] }) diff --git a/packages/tx/README.md b/packages/tx/README.md index f205171237..202bbef889 100644 --- a/packages/tx/README.md +++ b/packages/tx/README.md @@ -364,6 +364,7 @@ The following L2 networks have been tested to work with `@ethereumjs/tx`, see us | xDai Chain |  `Common.xDaiChain` |  [#1323](https://github.com/ethereumjs/ethereumjs-monorepo/issues/1323) | | Optimistic Kovan | `Common.OptimisticKovan` | [#1554](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1554) | | Optimistic Ethereum | `Common.OptimisticEthereum` | [#1554](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1554) | +| Polygon Amoy Testnet | `CustomChain.PolygonAmoy` | [#3379](https://github.com/ethereumjs/ethereumjs-monorepo/issues/3379) | Note: For Optimistic Kovan and Optimistic Ethereum, the London hardfork has not been implemented so transactions submitted with a `baseFee` will revert. The London hardfork is targeted to implement on Optimism in Q1.22.