Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon amoy support #3380

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/common/README.md
Expand Up @@ -257,6 +257,7 @@ The following custom chains are currently supported:

- `PolygonMainnet`
- `PolygonMumbai`
- `PolygonAmoy`
- `ArbitrumRinkebyTestnet`
- `xDaiChain`
- `OptimisticKovan`
Expand Down
15 changes: 15 additions & 0 deletions packages/common/docs/enums/CustomChain.md
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions packages/common/src/common.ts
Expand Up @@ -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(
{
Expand Down
7 changes: 7 additions & 0 deletions packages/common/src/enums.ts
Expand Up @@ -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',
}
46 changes: 46 additions & 0 deletions packages/common/test/customChains.spec.ts
Expand Up @@ -98,6 +98,52 @@ describe('[Common]: Custom chains', () => {
}
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you make any substantial changes in this new test other than change the custom chain reference on line 106 to PolygonAmoy? I don't see anything obvious so not sure we need a duplicate of the test above with a different chain name.

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[] })
Expand Down
1 change: 1 addition & 0 deletions packages/tx/README.md
Expand Up @@ -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) |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test and confirm that transactions created with our libraries are accepted and included in Amoy blocks?


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.
Expand Down