Skip to content

Commit

Permalink
Support signers and providers in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
germartinez committed Sep 16, 2022
1 parent 71b73d7 commit 4288a66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions packages/safe-core-sdk/tests/utils/setupEthAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { Signer } from '@ethersproject/abstract-signer'
import { Provider } from '@ethersproject/providers'
import { EthAdapter } from '@gnosis.pm/safe-core-sdk-types'
import EthersAdapter, { EthersAdapterConfig } from '@gnosis.pm/safe-ethers-lib'
import Web3Adapter, { Web3AdapterConfig } from '@gnosis.pm/safe-web3-lib'
import { ethers, web3 } from 'hardhat'

export async function getEthAdapter(signer: Signer): Promise<EthAdapter> {
export async function getEthAdapter(signerOrProvider: Signer | Provider): Promise<EthAdapter> {
let ethAdapter: EthAdapter
switch (process.env.ETH_LIB) {
case 'web3':
const signerAddress = await signer.getAddress()
const signerAddress = (signerOrProvider instanceof Signer)
? await signerOrProvider.getAddress()
: undefined
const web3AdapterConfig: Web3AdapterConfig = { web3: web3 as any, signerAddress }
ethAdapter = new Web3Adapter(web3AdapterConfig)
break
case 'ethers':
const ethersAdapterConfig: EthersAdapterConfig = { ethers, signer }
const ethersAdapterConfig: EthersAdapterConfig = { ethers, signerOrProvider }
ethAdapter = new EthersAdapter(ethersAdapterConfig)
break
default:
Expand Down
9 changes: 6 additions & 3 deletions packages/safe-service-client/tests/utils/setupEthAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { Signer } from '@ethersproject/abstract-signer'
import { Provider } from '@ethersproject/providers'
import { EthAdapter } from '@gnosis.pm/safe-core-sdk-types'
import EthersAdapter, { EthersAdapterConfig } from '@gnosis.pm/safe-ethers-lib'
import Web3Adapter, { Web3AdapterConfig } from '@gnosis.pm/safe-web3-lib'
import { ethers, web3 } from 'hardhat'

export async function getEthAdapter(signer: Signer): Promise<EthAdapter> {
export async function getEthAdapter(signerOrProvider: Signer | Provider): Promise<EthAdapter> {
let ethAdapter: EthAdapter
switch (process.env.ETH_LIB) {
case 'web3':
const signerAddress = await signer.getAddress()
const signerAddress = (signerOrProvider instanceof Signer)
? await signerOrProvider.getAddress()
: undefined
const web3AdapterConfig: Web3AdapterConfig = { web3: web3 as any, signerAddress }
ethAdapter = new Web3Adapter(web3AdapterConfig)
break
case 'ethers':
const ethersAdapterConfig: EthersAdapterConfig = { ethers, signer }
const ethersAdapterConfig: EthersAdapterConfig = { ethers, signerOrProvider }
ethAdapter = new EthersAdapter(ethersAdapterConfig)
break
default:
Expand Down

0 comments on commit 4288a66

Please sign in to comment.