-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba1d71f
commit ceea076
Showing
3 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { ActorSubclass } from "@dfinity/agent"; | ||
import { mock } from "jest-mock-extended"; | ||
import { _SERVICE as IndexService } from "../candid/index"; | ||
import { IndexCanister } from "./index.canister"; | ||
import { mockAccountIdentifier } from "./mocks/ledger.mock"; | ||
|
||
describe("IndexCanister", () => { | ||
describe("accountBalance", () => { | ||
const balanceMock = 30_000_000n; | ||
|
||
it("returns account balance with query call", async () => { | ||
const service = mock<ActorSubclass<IndexService>>(); | ||
service.get_account_identifier_balance.mockResolvedValue(balanceMock); | ||
const index = IndexCanister.create({ | ||
serviceOverride: service, | ||
}); | ||
|
||
const balance = await index.accountBalance({ | ||
accountIdentifier: mockAccountIdentifier, | ||
certified: false, | ||
}); | ||
expect(balance).toEqual(balanceMock); | ||
expect(service.get_account_identifier_balance).toBeCalled(); | ||
}); | ||
|
||
it("returns account balance with update call", async () => { | ||
const service = mock<ActorSubclass<IndexService>>(); | ||
service.get_account_identifier_balance.mockResolvedValue(balanceMock); | ||
const index = IndexCanister.create({ | ||
certifiedServiceOverride: service, | ||
}); | ||
|
||
const balance = await index.accountBalance({ | ||
accountIdentifier: mockAccountIdentifier, | ||
certified: true, | ||
}); | ||
expect(balance).toEqual(balanceMock); | ||
expect(service.get_account_identifier_balance).toBeCalled(); | ||
}); | ||
|
||
it("returns account balance with account identifier as hex", async () => { | ||
const service = mock<ActorSubclass<IndexService>>(); | ||
service.get_account_identifier_balance.mockResolvedValue(balanceMock); | ||
const index = IndexCanister.create({ | ||
serviceOverride: service, | ||
}); | ||
|
||
const balance = await index.accountBalance({ | ||
accountIdentifier: mockAccountIdentifier.toHex(), | ||
certified: false, | ||
}); | ||
expect(balance).toEqual(balanceMock); | ||
expect(service.get_account_identifier_balance).toBeCalled(); | ||
}); | ||
|
||
it("should bubble errors", () => { | ||
const service = mock<ActorSubclass<IndexService>>(); | ||
service.get_account_identifier_balance.mockImplementation(() => { | ||
throw new Error(); | ||
}); | ||
|
||
const index = IndexCanister.create({ | ||
serviceOverride: service, | ||
}); | ||
|
||
expect(() => | ||
index.accountBalance({ | ||
accountIdentifier: mockAccountIdentifier.toHex(), | ||
certified: false, | ||
}), | ||
).toThrowError(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { AccountIdentifier } from "../account_identifier"; | ||
|
||
export const mockAccountIdentifier = AccountIdentifier.fromHex( | ||
"3e8bbceef8b9338e56a1b561a127326e6614894ab9b0739df4cc3664d40a5958", | ||
); |