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

No longer expose test environment Hardhat ChainIds and NetworkConfigs #545

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { WalletRequestHandler, WindowMessageHandler } from '@0xsequence/provider'
import { Account } from '@0xsequence/account'
import { NetworkConfig } from '@0xsequence/network'
import { ChainId, NetworkConfig } from '@0xsequence/network'
import { LocalRelayer } from '@0xsequence/relayer'
import { configureLogger } from '@0xsequence/utils'

Expand Down Expand Up @@ -41,7 +41,7 @@ const main = async () => {
const networks: NetworkConfig[] = [
{
name: 'hardhat',
chainId: 31337,
chainId: 31337 as ChainId,
rpcUrl: provider.connection.url,
provider: provider,
relayer: relayer,
Expand All @@ -54,7 +54,7 @@ const main = async () => {
},
{
name: 'hardhat2',
chainId: 31338,
chainId: 31338 as ChainId,
rpcUrl: provider2.connection.url,
provider: provider2,
relayer: relayer2,
Expand Down
20 changes: 15 additions & 5 deletions packages/0xsequence/tests/browser/mux-transport/mux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@0xsequence/provider'
import { ethers } from 'ethers'
import { test, assert } from '../../utils/assert'
import { NetworkConfig } from '@0xsequence/network'
import { ChainId, NetworkConfig } from '@0xsequence/network'
import { LocalRelayer } from '@0xsequence/relayer'
import { configureLogger } from '@0xsequence/utils'
import { testAccounts, getEOAWallet } from '../testutils'
Expand Down Expand Up @@ -57,18 +57,28 @@ export const tests = async () => {
const networks: NetworkConfig[] = [
{
name: 'hardhat',
chainId: 31337,
chainId: 31337 as ChainId,
rpcUrl: provider1.connection.url,
provider: provider1,
relayer: relayer1,
isDefaultChain: true
isDefaultChain: true,
nativeToken: {
symbol: 'ETH',
name: 'Ether',
decimals: 18
}
},
{
name: 'hardhat2',
chainId: 31338,
chainId: 31338 as ChainId,
rpcUrl: provider2.connection.url,
provider: provider2,
relayer: relayer2
relayer: relayer2,
nativeToken: {
symbol: 'ETH',
name: 'Ether',
decimals: 18
}
}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as utils from '@0xsequence/tests'
import { Orchestrator } from '@0xsequence/signhub'
import { trackers } from '@0xsequence/sessions'
import { commons } from '@0xsequence/core'
import { ChainId } from '@0xsequence/network'

configureLogger({ logLevel: 'DEBUG', silence: false })

Expand Down Expand Up @@ -70,11 +71,16 @@ export const tests = async () => {
const networks = [
{
name: 'hardhat',
chainId: 31337,
chainId: 31337 as ChainId,
rpcUrl: rpcProvider.connection.url,
provider: rpcProvider,
relayer: relayer,
isDefaultChain: true
isDefaultChain: true,
nativeToken: {
symbol: 'ETH',
name: 'Ether',
decimals: 18
}
}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const tests = async () => {
assert.equal(networks.length, 2, '2 networks')
assert.true(networks[0].isDefaultChain!, '1st network is DefaultChain')
assert.true(!networks[1].isDefaultChain, '1st network is not DefaultChain')
assert.true(networks[1].chainId === 31338, 'authChainId is correct')
assert.equal(networks[1].chainId, 31338, 'authChainId is correct')

const authProvider = wallet.getProvider(31338)!
assert.equal(authProvider.getChainId(), 31338, 'authProvider chainId is 31338')
Expand Down
6 changes: 3 additions & 3 deletions packages/account/tests/account.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { walletContracts } from '@0xsequence/abi'
import { commons, v1, v2 } from '@0xsequence/core'
import { migrator } from '@0xsequence/migration'
import { NetworkConfig } from '@0xsequence/network'
import { ChainId, NetworkConfig } from '@0xsequence/network'
import { LocalRelayer, Relayer } from '@0xsequence/relayer'
import { tracker, trackers } from '@0xsequence/sessions'
import { Orchestrator } from '@0xsequence/signhub'
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('Account', () => {

networks = [
{
chainId: 31337,
chainId: 31337 as ChainId,
name: 'hardhat',
provider: provider1,
rpcUrl: '',
Expand All @@ -112,7 +112,7 @@ describe('Account', () => {
}
},
{
chainId: 31338,
chainId: 31338 as ChainId,
name: 'hardhat2',
provider: provider2,
rpcUrl: 'http://127.0.0.1:7048',
Expand Down
16 changes: 8 additions & 8 deletions packages/account/tests/signer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { commons, v1, v2 } from '@0xsequence/core'
import { migrator } from '@0xsequence/migration'
import { NetworkConfig } from '@0xsequence/network'
import { ChainId, NetworkConfig } from '@0xsequence/network'
import { FeeOption, FeeQuote, LocalRelayer, LocalRelayerOptions, Relayer, proto } from '@0xsequence/relayer'
import { tracker, trackers } from '@0xsequence/sessions'
import { Orchestrator } from '@0xsequence/signhub'
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('Account signer', () => {

networks = [
{
chainId: 31337,
chainId: 31337 as ChainId,
name: 'hardhat',
provider: provider1,
rpcUrl: '',
Expand All @@ -56,7 +56,7 @@ describe('Account signer', () => {
}
},
{
chainId: 31338,
chainId: 31338 as ChainId,
name: 'hardhat2',
provider: provider2,
rpcUrl: 'http://127.0.0.1:7048',
Expand Down Expand Up @@ -85,9 +85,9 @@ describe('Account signer', () => {
})

describe('with new account', () => {
var account: Account
var config: any
var accountSigner: ethers.Wallet
let account: Account
let config: any
let accountSigner: ethers.Wallet

beforeEach(async () => {
accountSigner = randomWallet('Should create a new account')
Expand Down Expand Up @@ -220,8 +220,8 @@ describe('Account signer', () => {
})

describe('select fee', () => {
var account: never
var getAccount: (feeOptions: FeeOption[], feeQuote: FeeQuote) => Promise<Account>
let account: never
let getAccount: (feeOptions: FeeOption[], feeQuote: FeeQuote) => Promise<Account>

beforeEach(async () => {
class LocalRelayerWithFee extends LocalRelayer {
Expand Down
20 changes: 0 additions & 20 deletions packages/network/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,5 @@ export const allNetworks = validateAndSortNetworks([
{
...networks[ChainId.TELOS],
...genUrls('telos')
},
{
...networks[ChainId.HARDHAT],
rpcUrl: 'http://localhost:8545',
relayer: {
url: 'http://localhost:3000',
provider: {
url: 'http://localhost:8545'
}
}
},
{
...networks[ChainId.HARDHAT_2],
rpcUrl: 'http://localhost:9545',
relayer: {
url: 'http://localhost:3000',
provider: {
url: 'http://localhost:9545'
}
}
}
])
48 changes: 22 additions & 26 deletions packages/network/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ export enum ChainId {
XR_SEPOLIA = 2730,

// TELOS
TELOS = 40,

// HARDHAT TESTNETS
HARDHAT = 31337,
HARDHAT_2 = 31338
TELOS = 40
}

export enum NetworkType {
Expand Down Expand Up @@ -672,26 +668,26 @@ export const networks: Record<ChainId, NetworkMetadata> = {
name: 'TLOS',
decimals: 18
}
},

[ChainId.HARDHAT]: {
chainId: ChainId.HARDHAT,
name: 'hardhat',
title: 'Hardhat (local testnet)',
nativeToken: {
symbol: 'ETH',
name: 'Ether',
decimals: 18
}
},
[ChainId.HARDHAT_2]: {
chainId: ChainId.HARDHAT_2,
name: 'hardhat2',
title: 'Hardhat (local testnet)',
nativeToken: {
symbol: 'ETH',
name: 'Ether',
decimals: 18
}
}

// [ChainId.HARDHAT]: {
// chainId: ChainId.HARDHAT,
// name: 'hardhat',
// title: 'Hardhat (local testnet)',
// nativeToken: {
// symbol: 'ETH',
// name: 'Ether',
// decimals: 18
// }
// },
// [ChainId.HARDHAT_2]: {
// chainId: ChainId.HARDHAT_2,
// name: 'hardhat2',
// title: 'Hardhat (local testnet)',
// nativeToken: {
// symbol: 'ETH',
// name: 'Ether',
// decimals: 18
// }
// }
}
11 changes: 8 additions & 3 deletions packages/provider/tests/provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SingleNetworkSequenceProvider
} from '../src'
import { expect } from 'chai'
import { JsonRpcRequest, JsonRpcResponse, allNetworks } from '@0xsequence/network'
import { ChainId, JsonRpcRequest, JsonRpcResponse, NetworkConfig, allNetworks } from '@0xsequence/network'
import { ExtendedTransactionRequest } from '../src/extended'

const hardhat1Provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:9595')
Expand Down Expand Up @@ -501,11 +501,16 @@ describe('SequenceProvider', () => {

it('should work when passing a full network config', () => {
expect(provider.toChainId(allNetworks.find(n => n.chainId === 1))).to.equal(1)
expect(provider.toChainId(allNetworks.find(n => n.chainId === 31337))).to.equal(31337)
expect(provider.toChainId(allNetworks.find(n => n.chainId === (31337 as ChainId)))).to.equal(31337)
})

it('should fail if the passed network config doesnt exist on the provider', () => {
const fakeNetwork = { chainId: 99999, name: 'fake', rpcUrl: 'http://127.0.0.1:99999' }
const fakeNetwork = {
chainId: 99999 as ChainId,
name: 'fake',
rpcUrl: 'http://127.0.0.1:99999',
nativeToken: { symbol: 'ETH', name: 'Ether', decimals: 18 }
}
expect(() => provider.toChainId(fakeNetwork)).to.throw(`Unsupported network ${fakeNetwork}`)
})

Expand Down
Loading