Skip to content

Commit

Permalink
Merge pull request #533 from bandada-infra/fix/min-balance
Browse files Browse the repository at this point in the history
Fix validate function in blockchain balance validator
  • Loading branch information
vplasencia authored Jun 27, 2024
2 parents 3504e95 + 2a38424 commit 45c1d07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ describe("BlockchainBalance", () => {
}

it("Should return true if an account has a balance greater than or equal to 10", async () => {
jsonRpcProviderMocked.getBalance.mockReturnValue(BigNumber.from(12))
jsonRpcProviderMocked.getBalance.mockReturnValue(
BigNumber.from("12000000000000000000")
)

const result = await validateCredentials(
{
Expand All @@ -28,7 +30,9 @@ describe("BlockchainBalance", () => {
})

it("Should return true if an account has a balance greater than or equal to 10 using the block number", async () => {
jsonRpcProviderMocked.getBalance.mockReturnValue(BigNumber.from(12))
jsonRpcProviderMocked.getBalance.mockReturnValue(
BigNumber.from("12000000000000000000")
)

const result = await validateCredentials(
{
Expand Down
9 changes: 6 additions & 3 deletions libs/credentials/src/validators/blockchainBalance/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber } from "ethers"
import { utils } from "ethers"
import { BlockchainContext, Validator } from "../.."

export type Criteria = {
Expand Down Expand Up @@ -38,13 +38,16 @@ const validator: Validator = {
? criteria.blockNumber
: undefined

const balance = await (
const balanceWei = await (
context as BlockchainContext
).jsonRpcProvider.getBalance(
(context as BlockchainContext).address,
blockNumber
)
return balance >= BigNumber.from(criteria.minBalance)

const balanceETH = utils.formatEther(balanceWei)

return parseFloat(balanceETH) >= parseFloat(criteria.minBalance)
}
throw new Error("No address value found")
}
Expand Down

0 comments on commit 45c1d07

Please sign in to comment.