-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose transaction crafting and estimation to third parties components (
#6583) * feat: add some tests Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: use fixtures everywhere Signed-off-by: Stéphane Prohaszka <[email protected]> * feat: use msw instead of mocking network lib calls Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: clean test Signed-off-by: Stéphane Prohaszka <[email protected]> * feat: separate core broadcast from bridge Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: add more tests Signed-off-by: Stéphane Prohaszka <[email protected]> * feat: expose estimateFees simpler version for Lama Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: separate more bridge dedicated logic from coin logic Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: separate bridge types from required ones to the core logic Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: add a lot of tests in signOperation Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: add test on getAccountShape Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: rename buildTransaction to better understanding of boundaries Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: add changeset Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: lint Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: revert export modifications Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: link error in LLD Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: some cleanup Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: revert unecessary modification Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: remove unecessary exposed test directory Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: try to solve ci test issue Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: feedbacks and type enforcement Signed-off-by: Stéphane Prohaszka <[email protected]> * fix nano app to latest non-generic * chore: revert changing on bot appcoin Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: freshAdresses remove Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: test flakiness and network cache Signed-off-by: Stéphane Prohaszka <[email protected]> --------- Signed-off-by: Stéphane Prohaszka <[email protected]> Co-authored-by: Hedi EDELBLOUTE <[email protected]>
- Loading branch information
1 parent
f317536
commit 83e5690
Showing
52 changed files
with
2,431 additions
and
843 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,8 @@ | ||
--- | ||
"@ledgerhq/coin-polkadot": minor | ||
"@ledgerhq/types-live": patch | ||
"@ledgerhq/live-common": patch | ||
"@ledgerhq/coin-framework": patch | ||
--- | ||
|
||
Expose Polkadot crafting functions to external components |
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,145 @@ | ||
import { Account, Operation, TokenAccount } from "@ledgerhq/types-live"; | ||
import { addPendingOperation } from "./pending"; | ||
import BigNumber from "bignumber.js"; | ||
import { listCryptoCurrencies } from "@ledgerhq/cryptoassets/index"; | ||
import { TokenCurrency } from "@ledgerhq/types-cryptoassets"; | ||
|
||
describe("addPendingOperation", () => { | ||
it("add the operation to the matching account Id", () => { | ||
// Given | ||
const account = createAccount("12"); | ||
const subAccount = createTokenAccount("12.1"); | ||
account.subAccounts = [subAccount]; | ||
const op = createOperation("12"); | ||
|
||
// When | ||
const result = addPendingOperation(account, op); | ||
|
||
// Then | ||
expect(result).not.toBe(account); | ||
expect(result.pendingOperations).toContain(op); | ||
const resultSubAcc = result?.subAccounts; | ||
expect(resultSubAcc).not.toBeFalsy(); | ||
expect(resultSubAcc).not.toBe(subAccount); | ||
expect(resultSubAcc![0].pendingOperations).not.toContain(op); | ||
}); | ||
|
||
it("add the operation to the matching subAccount Id", () => { | ||
// Given | ||
const account = createAccount("12"); | ||
const subAccount = createTokenAccount("12.1"); | ||
account.subAccounts = [subAccount]; | ||
const op = createOperation("12.1"); | ||
|
||
// When | ||
const result = addPendingOperation(account, op); | ||
|
||
// Then | ||
expect(result).not.toBe(account); | ||
expect(result.pendingOperations).not.toContain(op); | ||
const resultSubAcc = result?.subAccounts; | ||
expect(resultSubAcc).not.toBeFalsy(); | ||
expect(resultSubAcc).not.toBe(subAccount); | ||
expect(resultSubAcc![0].pendingOperations).toContain(op); | ||
}); | ||
|
||
it("lose an operation if the id doesn't match account and subaccount", () => { | ||
// Given | ||
const account = createAccount("12"); | ||
const subAccount = createTokenAccount("12.1"); | ||
account.subAccounts = [subAccount]; | ||
const op = createOperation("13"); | ||
|
||
// When | ||
const result = addPendingOperation(account, op); | ||
|
||
// Then | ||
expect(result).not.toBe(account); | ||
expect(result.pendingOperations).not.toContain(op); | ||
const resultSubAcc = result?.subAccounts; | ||
expect(resultSubAcc).not.toBeFalsy(); | ||
expect(resultSubAcc).not.toBe(subAccount); | ||
expect(resultSubAcc![0].pendingOperations).not.toContain(op); | ||
}); | ||
}); | ||
|
||
const emptyHistoryCache = { | ||
HOUR: { | ||
latestDate: null, | ||
balances: [], | ||
}, | ||
DAY: { | ||
latestDate: null, | ||
balances: [], | ||
}, | ||
WEEK: { | ||
latestDate: null, | ||
balances: [], | ||
}, | ||
}; | ||
|
||
function createAccount(id: string): Account { | ||
const currency = listCryptoCurrencies(true)[0]; | ||
|
||
return { | ||
type: "Account", | ||
id, | ||
seedIdentifier: "", | ||
derivationMode: "", | ||
index: 0, | ||
freshAddress: "", | ||
freshAddressPath: "", | ||
name: "", | ||
starred: false, | ||
used: true, | ||
balance: new BigNumber(0), | ||
spendableBalance: new BigNumber(0), | ||
creationDate: new Date(), | ||
blockHeight: 0, | ||
currency, | ||
unit: currency.units[0], | ||
operationsCount: 0, | ||
operations: [], | ||
pendingOperations: [], | ||
lastSyncDate: new Date(), | ||
// subAccounts: [], | ||
balanceHistoryCache: emptyHistoryCache, | ||
swapHistory: [], | ||
}; | ||
} | ||
|
||
function createTokenAccount(id: string): TokenAccount { | ||
return { | ||
type: "TokenAccount", | ||
id, | ||
parentId: "", | ||
token: {} as unknown as TokenCurrency, | ||
balance: new BigNumber(0), | ||
spendableBalance: new BigNumber(0), | ||
creationDate: new Date(), | ||
operationsCount: 0, | ||
operations: [], | ||
pendingOperations: [], | ||
starred: false, | ||
balanceHistoryCache: emptyHistoryCache, | ||
swapHistory: [], | ||
}; | ||
} | ||
|
||
function createOperation(accountId: string): Operation { | ||
return { | ||
id: "", | ||
hash: "", | ||
type: "ACTIVATE", | ||
value: new BigNumber(0), | ||
fee: new BigNumber(0), | ||
// senders & recipients addresses | ||
senders: [], | ||
recipients: [], | ||
blockHeight: undefined, | ||
blockHash: undefined, | ||
accountId, | ||
date: new Date(), | ||
extra: null, | ||
}; | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...coin-polkadot/src/logic/broadcast.test.ts → ...oin-polkadot/src/bridge/broadcast.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
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,18 @@ | ||
import type { Operation, SignedOperation } from "@ledgerhq/types-live"; | ||
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation"; | ||
import { broadcast as logicBroadcast } from "../logic"; | ||
|
||
/** | ||
* Broadcast the signed transaction | ||
* @param {signature: string, operation: string} signedOperation | ||
*/ | ||
const broadcast = async ({ | ||
signedOperation: { signature, operation }, | ||
}: { | ||
signedOperation: SignedOperation; | ||
}): Promise<Operation> => { | ||
const hash = await logicBroadcast(signature); | ||
return patchOperationWithHash(operation, hash); | ||
}; | ||
|
||
export default broadcast; |
Oops, something went wrong.