Skip to content

Commit

Permalink
connect ethers provider when querying deployer balance
Browse files Browse the repository at this point in the history
  • Loading branch information
haseebrabbani committed May 9, 2022
1 parent 8a30a76 commit c14b743
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cli/commands/publish/push.to.registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ describe("pushToRegistry", () => {
const mockManifestRef = "abc123"
const mockFromAddress = "0x123"
const mockChainIds = [1]
const mockEthersProvider = {

}
const mockFromWallet = {
getBalance: jest.fn(),
connect: jest.fn().mockReturnThis(),
address: mockFromAddress
}

Expand All @@ -26,7 +30,7 @@ describe("pushToRegistry", () => {
}

beforeAll(() => {
pushToRegistry = providePushToRegistry(mockAppendToFile, mockAgentRegistry as any, mockAgentId, mockChainIds)
pushToRegistry = providePushToRegistry(mockAppendToFile, mockAgentRegistry as any, mockAgentId, mockChainIds, mockEthersProvider as any)
})

beforeEach(() => resetMocks())
Expand All @@ -39,6 +43,8 @@ describe("pushToRegistry", () => {
await pushToRegistry(mockManifestRef, mockFromWallet as any)
} catch (e) {
expect(e.message).toBe(`insufficient balance to deploy agent for ${mockFromWallet.address}`)
expect(mockFromWallet.connect).toHaveBeenCalledTimes(1)
expect(mockFromWallet.connect).toHaveBeenCalledWith(mockEthersProvider)
}
})

Expand Down
8 changes: 5 additions & 3 deletions cli/commands/publish/push.to.registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Wallet } from "ethers"
import { Wallet, providers } from "ethers"
import { assertExists, assertIsNonEmptyString } from "../../utils"
import { AppendToFile } from '../../utils/append.to.file'
import AgentRegistry from "../../contracts/agent.registry"
Expand All @@ -10,17 +10,19 @@ export default function providePushToRegistry(
appendToFile: AppendToFile,
agentRegistry: AgentRegistry,
agentId: string,
chainIds: number[]
chainIds: number[],
ethersAgentRegistryProvider: providers.JsonRpcProvider
): PushToRegistry {
assertExists(appendToFile, 'appendToFile')
assertExists(agentRegistry, 'agentRegistry')
assertIsNonEmptyString(agentId, 'agentId')
assertExists(chainIds, 'chainIds')
assertExists(ethersAgentRegistryProvider, 'ethersAgentRegistryProvider')

return async function pushToRegistry(manifestReference: string, fromWallet: Wallet) {
const [agent, fromWalletBalance] = await Promise.all([
agentRegistry.getAgent(agentId),
fromWallet.getBalance()
fromWallet.connect(ethersAgentRegistryProvider).getBalance()
])
const agentExists = agent.created
// verify wallet has some balance to pay transaction fee
Expand Down

0 comments on commit c14b743

Please sign in to comment.