Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Jul 17, 2024
1 parent 6be0da1 commit b05ba05
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 49 deletions.
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 @@ -176,24 +176,4 @@ 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'
// }
// }
// }
])
4 changes: 0 additions & 4 deletions packages/network/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export enum ChainId {

// TELOS
TELOS = 40

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

export enum NetworkType {
Expand Down
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

0 comments on commit b05ba05

Please sign in to comment.