-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(xrp): return 0 as default balance (#8242)
* fix(xrp): return 0 as default balance * fix: update account info management for alpaca Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr> * chore: changeset Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr> * fix(xrp): sync AccountInfo model use Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr> --------- Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr> Co-authored-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>
- Loading branch information
1 parent
5b7c59d
commit 901cdd5
Showing
13 changed files
with
253 additions
and
29 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,5 @@ | ||
--- | ||
"@ledgerhq/coin-xrp": patch | ||
--- | ||
|
||
Fix Cardano getAccountInfo |
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
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
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,60 @@ | ||
import { cachedRecipientIsNew } from "./utils"; | ||
|
||
jest.mock("ripple-address-codec", () => ({ | ||
isValidClassicAddress: () => true, | ||
})); | ||
const mockGetAccountInfo = jest.fn(); | ||
jest.mock("../network", () => ({ | ||
getAccountInfo: (address: string) => mockGetAccountInfo(address), | ||
})); | ||
|
||
describe("cachedRecipientIsNew", () => { | ||
afterEach(() => { | ||
mockGetAccountInfo.mockClear(); | ||
}); | ||
|
||
it("returns true when network returns a new empty account", async () => { | ||
// Given | ||
mockGetAccountInfo.mockResolvedValueOnce({ | ||
isNewAccount: true, | ||
balance: "0", | ||
ownerCount: 0, | ||
sequence: 0, | ||
}); | ||
|
||
// When | ||
const result = await cachedRecipientIsNew("address1"); | ||
|
||
// Then | ||
expect(mockGetAccountInfo).toHaveBeenCalledTimes(1); | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
it("returns false when network a valid AccountInfo", async () => { | ||
// Given | ||
mockGetAccountInfo.mockResolvedValueOnce({ | ||
isNewAccount: false, | ||
balance: "999441667919804", | ||
ownerCount: 0, | ||
sequence: 999441667919804, | ||
}); | ||
|
||
// When | ||
const result = await cachedRecipientIsNew("address2"); | ||
|
||
// Then | ||
expect(mockGetAccountInfo).toHaveBeenCalledTimes(1); | ||
expect(result).toBeFalsy(); | ||
}); | ||
|
||
it("throws an error when network throws an error", async () => { | ||
// Given | ||
mockGetAccountInfo.mockImplementationOnce(() => { | ||
throw new Error("Malformed address"); | ||
}); | ||
|
||
// When & Then | ||
await expect(cachedRecipientIsNew("address3")).rejects.toThrow("Malformed address"); | ||
expect(mockGetAccountInfo).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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,114 @@ | ||
import network from "@ledgerhq/live-network"; | ||
import { getAccountInfo } from "."; | ||
import coinConfig, { type XrpCoinConfig } from "../config"; | ||
|
||
jest.mock("@ledgerhq/live-network"); | ||
|
||
describe("getAccountInfo", () => { | ||
beforeAll(() => { | ||
coinConfig.setCoinConfig( | ||
() => | ||
({ | ||
node: "", | ||
}) as XrpCoinConfig, | ||
); | ||
}); | ||
|
||
it("returns an empty AccountInfo when returns an error 'actNotFound'", async () => { | ||
// Given | ||
const emptyAddress = "rNCgVpHinUDjXP2vHDFDMjm7ssBwpveHya"; | ||
(network as jest.Mock).mockResolvedValue({ | ||
data: { | ||
result: { | ||
account: emptyAddress, | ||
error: "actNotFound", | ||
error_code: 19, | ||
error_message: "Account not found.", | ||
ledger_hash: "F2E6EFD279C3663B62D9DC9977106EC25BA8F89DA551C2D7AB3AE5D75B146258", | ||
ledger_index: 91772714, | ||
request: { | ||
account: emptyAddress, | ||
command: "account_info", | ||
ledger_index: "validated", | ||
}, | ||
status: "error", | ||
validated: true, | ||
}, | ||
}, | ||
}); | ||
|
||
// When | ||
const result = await getAccountInfo(emptyAddress); | ||
|
||
// Then | ||
expect(result).toEqual({ | ||
isNewAccount: true, | ||
balance: "0", | ||
ownerCount: 0, | ||
sequence: 0, | ||
}); | ||
}); | ||
|
||
it("returns a valid AccountInfo when return a correct AccountInfo", async () => { | ||
// Given | ||
const address = "rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb"; | ||
(network as jest.Mock).mockResolvedValue({ | ||
data: { | ||
result: { | ||
account_data: { | ||
Account: address, | ||
Balance: "999441667919804", | ||
Flags: 0, | ||
LedgerEntryType: "AccountRoot", | ||
OwnerCount: 0, | ||
PreviousTxnID: "947F03794C982FE4C7C9FECC4C33C543BB25B82938895EBA8F9B6021CC27A571", | ||
PreviousTxnLgrSeq: 725208, | ||
Sequence: 153743, | ||
index: "BC0DAE09C0BFBC4A49AA94B849266588BFD6E1F554B184B5788AC55D6E07EB95", | ||
}, | ||
ledger_hash: "93E952B2770233B0ABFBFBBFBC3E2E2159DCABD07FEB5F4C49174027935D9FBB", | ||
ledger_index: 1908009, | ||
status: "success", | ||
validated: true, | ||
}, | ||
}, | ||
}); | ||
|
||
// When | ||
const result = await getAccountInfo(address); | ||
|
||
// Then | ||
expect(result).toEqual({ | ||
isNewAccount: false, | ||
balance: "999441667919804", | ||
ownerCount: 0, | ||
sequence: 153743, | ||
}); | ||
}); | ||
|
||
it("throws an error when backend returns any other error", async () => { | ||
// Given | ||
const invalidAddress = "rNCgVpHinUDjXP2vHDFDMjm7ssBwpveHyaa"; | ||
(network as jest.Mock).mockResolvedValue({ | ||
result: { | ||
error: "actMalformed", | ||
error_code: 35, | ||
error_message: "Account malformed.", | ||
ledger_hash: "87DE2DD287BCAD6E81720BC6E6361EF01A66EE70A37B6BDF1EFF2E719D9410AE", | ||
ledger_index: 91772741, | ||
request: { | ||
account: invalidAddress, | ||
command: "account_info", | ||
ledger_index: "validated", | ||
}, | ||
status: "error", | ||
validated: true, | ||
}, | ||
}); | ||
|
||
// When & Then | ||
await expect(getAccountInfo(invalidAddress)).rejects.toThrow( | ||
"Cannot read properties of undefined (reading 'result')", | ||
); | ||
}); | ||
}); |
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
Oops, something went wrong.
901cdd5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Bot] Weekly non-reg on develop with 'Oxygen' ✅ 25 txs ❌ 6 txs 💰 2 miss funds ($377.23) ⏲ 12min 6s
5 critical spec errors
Spec Filecoin failed!
Spec cardano failed!
Spec secret_network failed!
Spec Telos failed!
Spec Polkadot failed!
❌ 6 mutation errors
Please increase the account target to at least 6 accounts
Please increase the account target to at least 4 accounts
Details of the 31 mutations
Spec Filecoin (0)
Spec Qtum (6)
Spec Decred (5)
Spec cardano (failed)
Spec axelar (18)
Spec cosmos (16)
Spec secret_network (failed)
Spec Avalanche C-Chain (10)
Spec Binance Smart Chain (10)
Spec Cronos (6)
Spec Fantom (6)
Spec Boba (failed)
Spec Telos (failed)
Spec Polygon zkEVM (5)
Spec Polkadot (failed)
Spec Tron (11)
Details of the 41 uncovered mutations
Spec Filecoin (5)
Spec Qtum (1)
Spec Decred (3)
Spec cardano (6)
Spec axelar (1)
Spec cosmos (2)
Spec secret_network (6)
Spec Binance Smart Chain (1)
Spec Cronos (3)
Spec Fantom (1)
Spec Boba (3)
Spec Telos (2)
Spec Polkadot (7)
Portfolio ($377.23) – Details of the 16 currencies
MRXjbrG85aWAD8g764s6kgj59156pg8mE8
DsUb8NAm1qfcmjrZNg6eFfsULiUDYbU6DLb
axelar123r3dwfylykx0fugawn6mu2h2smq3047pn5n9g
cosmos123r3dwfylykx0fugawn6mu2h2smq30479azmwf
0x731477De13B323A0cA90C1FE194EA5A0412937c2
0x731477De13B323A0cA90C1FE194EA5A0412937c2
0x731477De13B323A0cA90C1FE194EA5A0412937c2
0x731477De13B323A0cA90C1FE194EA5A0412937c2
0x731477De13B323A0cA90C1FE194EA5A0412937c2
0x731477De13B323A0cA90C1FE194EA5A0412937c2
TT2eHJXo5tRV2wYyZExr9W18mXghe6NFM1
Performance ⏲ 12min 6s
Time spent for each spec: (total across mutations)