-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9126 from LedgerHQ/fix_tezos
fix(coin:tezos): handle missing recipients or senders cleanly
- Loading branch information
Showing
4 changed files
with
131 additions
and
7 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-tezos": patch | ||
--- | ||
|
||
Fix addresses on operations |
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
101 changes: 101 additions & 0 deletions
101
libs/coin-modules/coin-tezos/src/logic/listOperations.test.ts
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,101 @@ | ||
import { listOperations } from "./listOperations"; | ||
import { APIDelegationType, APITransactionType } from "../network/types"; | ||
|
||
const mockNetworkGetTransactions = jest.fn(); | ||
jest.mock("../network", () => ({ | ||
tzkt: { | ||
getAccountOperations: async () => { | ||
return mockNetworkGetTransactions(); | ||
}, | ||
}, | ||
})); | ||
|
||
describe("listOperations", () => { | ||
afterEach(() => { | ||
mockNetworkGetTransactions.mockClear(); | ||
}); | ||
|
||
it("should return no operations", async () => { | ||
// Given | ||
mockNetworkGetTransactions.mockResolvedValue([]); | ||
// When | ||
const [results, token] = await listOperations("any address", {}); | ||
// Then | ||
expect(results).toEqual([]); | ||
expect(token).toEqual(""); | ||
}); | ||
|
||
const someDestinationAddress = "tz3Vq38qYD3GEbWcXHMLt5PaASZrkDtEiA8D"; | ||
const someSenderAddress = "tz2CVMDVA16dD9A7kpWym2ptGDhs5zUhwWXr"; | ||
const delegate: APIDelegationType = { | ||
type: "delegation", | ||
id: 111, | ||
level: 2702551, | ||
block: "BMJ1ZQ6", | ||
timestamp: "2022-09-12T01:36:59Z", | ||
amount: 724846, | ||
sender: { | ||
address: someSenderAddress, | ||
}, | ||
counter: 65214462, | ||
prevDelegate: { | ||
address: someDestinationAddress, | ||
}, | ||
newDelegate: null, | ||
}; | ||
|
||
const undelegate: APIDelegationType = { | ||
...delegate, | ||
id: 222, | ||
prevDelegate: null, | ||
newDelegate: { address: someDestinationAddress }, | ||
}; | ||
|
||
const transfer: APITransactionType = { | ||
...delegate, | ||
id: 333, | ||
initiator: null, | ||
type: "transaction", | ||
target: { address: someDestinationAddress }, | ||
}; | ||
|
||
it.each([undelegate, delegate, transfer])( | ||
"should return operation with proper recipient list", | ||
async operation => { | ||
// Given | ||
mockNetworkGetTransactions.mockResolvedValue([operation]); | ||
// When | ||
const [results, token] = await listOperations("any address", {}); | ||
// Then | ||
expect(results.length).toEqual(1); | ||
expect(results[0].recipients).toEqual([someDestinationAddress]); | ||
expect(token).toEqual(JSON.stringify(operation.id)); | ||
}, | ||
); | ||
|
||
it.each([ | ||
{ ...undelegate, newDelegate: null, prevDelegate: null }, | ||
{ ...transfer, target: null }, | ||
])("should return empty recipient list when no target can be found", async operation => { | ||
// Given | ||
mockNetworkGetTransactions.mockResolvedValue([operation]); | ||
// When | ||
const [results, token] = await listOperations("any address", {}); | ||
// Then | ||
expect(results.length).toEqual(1); | ||
expect(results[0].recipients).toEqual([]); | ||
expect(token).toEqual(JSON.stringify(operation.id)); | ||
}); | ||
|
||
it("should return empty sender list when no sender can be found", async () => { | ||
// Given | ||
const operation = { ...undelegate, sender: null }; | ||
mockNetworkGetTransactions.mockResolvedValue([operation]); | ||
// When | ||
const [results, token] = await listOperations("any address", {}); | ||
// Then | ||
expect(results.length).toEqual(1); | ||
expect(results[0].senders).toEqual([]); | ||
expect(token).toEqual(JSON.stringify(operation.id)); | ||
}); | ||
}); |
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