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

Signer recognition issue #735

Merged
merged 5 commits into from
Nov 6, 2023
Merged
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
4 changes: 2 additions & 2 deletions typescript/src/lib/ethereum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function ethereumNetworkFromSigner(
signer: EthereumSigner
): Promise<EthereumNetwork> {
let chainId: number
if (signer instanceof Signer) {
if (Signer.isSigner(signer)) {
chainId = await signer.getChainId()
} else {
const network = await signer.getNetwork()
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function ethereumNetworkFromSigner(
export async function ethereumAddressFromSigner(
signer: EthereumSigner
): Promise<EthereumAddress | undefined> {
if (signer instanceof Signer) {
if (Signer.isSigner(signer)) {
return EthereumAddress.from(await signer.getAddress())
} else {
return undefined
Expand Down
40 changes: 39 additions & 1 deletion typescript/test/lib/ethereum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import {
EthereumAddress,
EthereumBridge,
EthereumTBTCToken,
ethereumAddressFromSigner,
ethereumNetworkFromSigner,
Hex,
} from "../../src"
import {
deployMockContract,
MockContract,
} from "@ethereum-waffle/mock-contract"
import chai, { assert, expect } from "chai"
import { BigNumber, Wallet, constants, utils } from "ethers"
import { BigNumber, Wallet, constants, getDefaultProvider, utils } from "ethers"
import { abi as BridgeABI } from "@keep-network/tbtc-v2/artifacts/Bridge.json"
import { abi as TBTCTokenABI } from "@keep-network/tbtc-v2/artifacts/TBTC.json"
import { abi as WalletRegistryABI } from "@keep-network/ecdsa/artifacts/WalletRegistry.json"
Expand Down Expand Up @@ -591,4 +593,40 @@ describe("Ethereum", () => {
})
})
})

describe("ethereumAddressFromSigner", () => {
context("when the signer is a wallet", () => {
const [mockSigner] = new MockProvider().getWallets()
it("should return the signer's address", async () => {
expect(await ethereumAddressFromSigner(mockSigner)).to.be.eql(
EthereumAddress.from(mockSigner.address)
)
})
})

context("when the signer is a provider", () => {
const mockProvider = getDefaultProvider()
it("should return undefined", async () => {
expect(await ethereumAddressFromSigner(mockProvider)).to.be.undefined
})
})
})

describe("ethereumNetworkFromSigner", () => {
context("when the signer is a wallet", () => {
const [mockSigner] = new MockProvider().getWallets()
it("should return the signer's network", async () => {
expect(await ethereumNetworkFromSigner(mockSigner)).to.be.eql("local")
})
})

context("when the signer is a provider", () => {
const mockProvider = getDefaultProvider()
it("should return the signer's network", async () => {
expect(await ethereumNetworkFromSigner(mockProvider)).to.be.eql(
"mainnet"
)
})
})
})
})