@ledgerhq/coin-canton 0.5.0-nightly.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +32 -47
- package/lib/api/getBalance.integ.test.js +5 -9
- package/lib/api/getBalance.integ.test.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +25 -20
- package/lib/api/index.js.map +1 -1
- package/lib/api/lastBlock.integ.test.js +1 -1
- package/lib/api/lastBlock.integ.test.js.map +1 -1
- package/lib/api/listOperations.integ.test.js +1 -1
- package/lib/api/listOperations.integ.test.js.map +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +2 -3
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/broadcast.test.js +0 -9
- package/lib/bridge/broadcast.test.js.map +1 -1
- package/lib/bridge/createTransaction.js +1 -1
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/getTransactionStatus.js +1 -1
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +0 -3
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/onboard.d.ts +5 -7
- package/lib/bridge/onboard.d.ts.map +1 -1
- package/lib/bridge/onboard.integ.test.js +11 -14
- package/lib/bridge/onboard.integ.test.js.map +1 -1
- package/lib/bridge/onboard.js +42 -110
- package/lib/bridge/onboard.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +7 -5
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +11 -14
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/sync.d.ts +1 -2
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.js +21 -41
- package/lib/bridge/sync.js.map +1 -1
- package/lib/bridge/updateTransaction.d.ts.map +1 -1
- package/lib/bridge/updateTransaction.js +4 -0
- package/lib/bridge/updateTransaction.js.map +1 -1
- package/lib/common-logic/account/getBalance.d.ts +1 -2
- package/lib/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib/common-logic/account/getBalance.js +7 -7
- package/lib/common-logic/account/getBalance.js.map +1 -1
- package/lib/common-logic/account/getBalance.unit.test.js +3 -6
- package/lib/common-logic/account/getBalance.unit.test.js.map +1 -1
- package/lib/common-logic/history/lastBlock.d.ts +1 -2
- package/lib/common-logic/history/lastBlock.d.ts.map +1 -1
- package/lib/common-logic/history/lastBlock.js +3 -3
- package/lib/common-logic/history/lastBlock.js.map +1 -1
- package/lib/common-logic/history/lastBlock.test.js +2 -5
- package/lib/common-logic/history/lastBlock.test.js.map +1 -1
- package/lib/common-logic/history/listOperations.d.ts +1 -2
- package/lib/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib/common-logic/history/listOperations.js +2 -2
- package/lib/common-logic/history/listOperations.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.d.ts +1 -2
- package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib/common-logic/transaction/broadcast.js +4 -5
- package/lib/common-logic/transaction/broadcast.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.test.js +5 -8
- package/lib/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib/common-logic/transaction/combine.d.ts +1 -1
- package/lib/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib/common-logic/transaction/combine.js +3 -2
- package/lib/common-logic/transaction/combine.js.map +1 -1
- package/lib/common-logic/transaction/combine.test.js +13 -3
- package/lib/common-logic/transaction/combine.test.js.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.d.ts +4 -8
- package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.js +12 -15
- package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib/common-logic/transaction/estimateFees.d.ts +1 -2
- package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib/common-logic/transaction/estimateFees.js +3 -7
- package/lib/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib/config.d.ts +0 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/network/gateway.d.ts +17 -41
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.integ.test.js +15 -19
- package/lib/network/gateway.integ.test.js.map +1 -1
- package/lib/network/gateway.js +48 -74
- package/lib/network/gateway.js.map +1 -1
- package/lib/network/node.d.ts +2 -2
- package/lib/network/node.d.ts.map +1 -1
- package/lib/network/node.js.map +1 -1
- package/lib/network/types.d.ts +1 -1
- package/lib/network/types.d.ts.map +1 -1
- package/lib/signer/getAddress.d.ts.map +1 -1
- package/lib/signer/getAddress.js +2 -2
- package/lib/signer/getAddress.js.map +1 -1
- package/lib/types/bridge.d.ts +3 -18
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/index.d.ts +10 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/onboard.d.ts +0 -2
- package/lib/types/onboard.d.ts.map +1 -1
- package/lib/types/onboard.js.map +1 -1
- package/lib/types/signer.d.ts +1 -2
- package/lib/types/signer.d.ts.map +1 -1
- package/lib-es/api/getBalance.integ.test.js +5 -9
- package/lib-es/api/getBalance.integ.test.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +24 -19
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/lastBlock.integ.test.js +1 -1
- package/lib-es/api/lastBlock.integ.test.js.map +1 -1
- package/lib-es/api/listOperations.integ.test.js +1 -1
- package/lib-es/api/listOperations.integ.test.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +2 -3
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/broadcast.test.js +0 -9
- package/lib-es/bridge/broadcast.test.js.map +1 -1
- package/lib-es/bridge/createTransaction.js +1 -1
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +1 -1
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +0 -3
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/onboard.d.ts +5 -7
- package/lib-es/bridge/onboard.d.ts.map +1 -1
- package/lib-es/bridge/onboard.integ.test.js +11 -14
- package/lib-es/bridge/onboard.integ.test.js.map +1 -1
- package/lib-es/bridge/onboard.js +42 -107
- package/lib-es/bridge/onboard.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +8 -6
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +12 -15
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/sync.d.ts +1 -2
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.js +22 -42
- package/lib-es/bridge/sync.js.map +1 -1
- package/lib-es/bridge/updateTransaction.d.ts.map +1 -1
- package/lib-es/bridge/updateTransaction.js +4 -0
- package/lib-es/bridge/updateTransaction.js.map +1 -1
- package/lib-es/common-logic/account/getBalance.d.ts +1 -2
- package/lib-es/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib-es/common-logic/account/getBalance.js +7 -7
- package/lib-es/common-logic/account/getBalance.js.map +1 -1
- package/lib-es/common-logic/account/getBalance.unit.test.js +3 -6
- package/lib-es/common-logic/account/getBalance.unit.test.js.map +1 -1
- package/lib-es/common-logic/history/lastBlock.d.ts +1 -2
- package/lib-es/common-logic/history/lastBlock.d.ts.map +1 -1
- package/lib-es/common-logic/history/lastBlock.js +3 -3
- package/lib-es/common-logic/history/lastBlock.js.map +1 -1
- package/lib-es/common-logic/history/lastBlock.test.js +2 -5
- package/lib-es/common-logic/history/lastBlock.test.js.map +1 -1
- package/lib-es/common-logic/history/listOperations.d.ts +1 -2
- package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib-es/common-logic/history/listOperations.js +2 -2
- package/lib-es/common-logic/history/listOperations.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.d.ts +1 -2
- package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.js +4 -5
- package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.test.js +5 -8
- package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.d.ts +1 -1
- package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/combine.js +3 -2
- package/lib-es/common-logic/transaction/combine.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.test.js +13 -3
- package/lib-es/common-logic/transaction/combine.test.js.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.d.ts +4 -8
- package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js +12 -15
- package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.d.ts +1 -2
- package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.js +3 -4
- package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib-es/config.d.ts +0 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/network/gateway.d.ts +17 -41
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.integ.test.js +15 -19
- package/lib-es/network/gateway.integ.test.js.map +1 -1
- package/lib-es/network/gateway.js +48 -73
- package/lib-es/network/gateway.js.map +1 -1
- package/lib-es/network/node.d.ts +2 -2
- package/lib-es/network/node.d.ts.map +1 -1
- package/lib-es/network/node.js.map +1 -1
- package/lib-es/network/types.d.ts +1 -1
- package/lib-es/network/types.d.ts.map +1 -1
- package/lib-es/signer/getAddress.d.ts.map +1 -1
- package/lib-es/signer/getAddress.js +2 -2
- package/lib-es/signer/getAddress.js.map +1 -1
- package/lib-es/types/bridge.d.ts +3 -18
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/index.d.ts +10 -0
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/onboard.d.ts +0 -2
- package/lib-es/types/onboard.d.ts.map +1 -1
- package/lib-es/types/onboard.js.map +1 -1
- package/lib-es/types/signer.d.ts +1 -2
- package/lib-es/types/signer.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/api/getBalance.integ.test.ts +6 -9
- package/src/api/index.ts +44 -22
- package/src/api/lastBlock.integ.test.ts +1 -1
- package/src/api/listOperations.integ.test.ts +1 -1
- package/src/bridge/broadcast.test.ts +0 -11
- package/src/bridge/broadcast.ts +2 -4
- package/src/bridge/createTransaction.ts +1 -1
- package/src/bridge/getTransactionStatus.ts +1 -1
- package/src/bridge/index.ts +0 -3
- package/src/bridge/onboard.integ.test.ts +13 -25
- package/src/bridge/onboard.ts +51 -143
- package/src/bridge/prepareTransaction.ts +15 -6
- package/src/bridge/signOperation.ts +20 -26
- package/src/bridge/sync.ts +27 -53
- package/src/bridge/updateTransaction.ts +5 -0
- package/src/common-logic/account/getBalance.ts +7 -12
- package/src/common-logic/account/getBalance.unit.test.ts +3 -8
- package/src/common-logic/history/lastBlock.test.ts +2 -7
- package/src/common-logic/history/lastBlock.ts +3 -5
- package/src/common-logic/history/listOperations.ts +2 -3
- package/src/common-logic/transaction/broadcast.test.ts +5 -10
- package/src/common-logic/transaction/broadcast.ts +3 -7
- package/src/common-logic/transaction/combine.test.ts +13 -3
- package/src/common-logic/transaction/combine.ts +4 -2
- package/src/common-logic/transaction/craftTransaction.ts +15 -30
- package/src/common-logic/transaction/estimateFees.ts +3 -7
- package/src/config.ts +0 -1
- package/src/network/gateway.integ.test.ts +12 -31
- package/src/network/gateway.ts +62 -141
- package/src/network/node.ts +3 -3
- package/src/network/types.ts +1 -1
- package/src/signer/getAddress.ts +4 -6
- package/src/types/bridge.ts +0 -21
- package/src/types/index.ts +11 -0
- package/src/types/onboard.ts +0 -3
- package/src/types/signer.ts +1 -2
- package/lib/bridge/serialization.d.ts +0 -4
- package/lib/bridge/serialization.d.ts.map +0 -1
- package/lib/bridge/serialization.js +0 -31
- package/lib/bridge/serialization.js.map +0 -1
- package/lib/bridge/sync.integ.test.d.ts +0 -2
- package/lib/bridge/sync.integ.test.d.ts.map +0 -1
- package/lib/bridge/sync.integ.test.js +0 -175
- package/lib/bridge/sync.integ.test.js.map +0 -1
- package/lib-es/bridge/serialization.d.ts +0 -4
- package/lib-es/bridge/serialization.d.ts.map +0 -1
- package/lib-es/bridge/serialization.js +0 -27
- package/lib-es/bridge/serialization.js.map +0 -1
- package/lib-es/bridge/sync.integ.test.d.ts +0 -2
- package/lib-es/bridge/sync.integ.test.d.ts.map +0 -1
- package/lib-es/bridge/sync.integ.test.js +0 -137
- package/lib-es/bridge/sync.integ.test.js.map +0 -1
- package/src/bridge/serialization.ts +0 -36
- package/src/bridge/sync.integ.test.ts +0 -180
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assignToAccountRaw = assignToAccountRaw;
|
|
4
|
-
exports.assignFromAccountRaw = assignFromAccountRaw;
|
|
5
|
-
function toResourcesRaw(r) {
|
|
6
|
-
const { partyId } = r;
|
|
7
|
-
return {
|
|
8
|
-
partyId,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function fromResourcesRaw(r) {
|
|
12
|
-
const { partyId } = r;
|
|
13
|
-
return {
|
|
14
|
-
partyId,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function assignToAccountRaw(account, accountRaw) {
|
|
18
|
-
const cantonAccount = account;
|
|
19
|
-
const cantonAccountRaw = accountRaw;
|
|
20
|
-
if (cantonAccount.cantonResources) {
|
|
21
|
-
cantonAccountRaw.cantonResources = toResourcesRaw(cantonAccount.cantonResources);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function assignFromAccountRaw(accountRaw, account) {
|
|
25
|
-
const cantonResourcesRaw = accountRaw.cantonResources;
|
|
26
|
-
const cantonAccount = account;
|
|
27
|
-
if (cantonResourcesRaw) {
|
|
28
|
-
cantonAccount.cantonResources = fromResourcesRaw(cantonResourcesRaw);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=serialization.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["../../src/bridge/serialization.ts"],"names":[],"mappings":";;AAqBA,gDAMC;AAED,oDAMC;AA3BD,SAAS,cAAc,CAAC,CAAkB;IACxC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACtB,OAAO;QACL,OAAO;KACR,CAAC;AACJ,CAAC;AACD,SAAS,gBAAgB,CAAC,CAAqB;IAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACtB,OAAO;QACL,OAAO;KACR,CAAC;AACJ,CAAC;AAED,SAAgB,kBAAkB,CAAC,OAAgB,EAAE,UAAsB;IACzE,MAAM,aAAa,GAAG,OAAwB,CAAC;IAC/C,MAAM,gBAAgB,GAAG,UAA8B,CAAC;IACxD,IAAI,aAAa,CAAC,eAAe,EAAE,CAAC;QAClC,gBAAgB,CAAC,eAAe,GAAG,cAAc,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IACnF,CAAC;AACH,CAAC;AAED,SAAgB,oBAAoB,CAAC,UAAsB,EAAE,OAAgB;IAC3E,MAAM,kBAAkB,GAAI,UAA+B,CAAC,eAAe,CAAC;IAC5E,MAAM,aAAa,GAAG,OAAwB,CAAC;IAC/C,IAAI,kBAAkB,EAAE,CAAC;QACvB,aAAa,CAAC,eAAe,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;IACvE,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync.integ.test.d.ts","sourceRoot":"","sources":["../../src/bridge/sync.integ.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
40
|
-
const derivation_1 = require("@ledgerhq/coin-framework/derivation");
|
|
41
|
-
const currencies_1 = require("@ledgerhq/cryptoassets/currencies");
|
|
42
|
-
const config_1 = __importDefault(require("../config"));
|
|
43
|
-
const gateway = __importStar(require("../network/gateway"));
|
|
44
|
-
const sync_1 = require("./sync");
|
|
45
|
-
const TEST_ADDRESS = "b6400f93ea1c74aea86be39b0ccc846fc5de01f12b2ad0d7c31848d6fb6eb6d9::1220c81315e2bf2524a9141bcc6cbf19b61c151e0dcaa95343c0ccf53aed7415c4ec";
|
|
46
|
-
const currency = (0, currencies_1.getCryptoCurrencyById)("canton_network");
|
|
47
|
-
const derivationMode = (0, derivation_1.getDerivationModesForCurrency)(currency)[0];
|
|
48
|
-
const derivationPath = (0, derivation_1.runDerivationScheme)((0, derivation_1.getDerivationScheme)({ derivationMode, currency }), currency, {
|
|
49
|
-
account: 0,
|
|
50
|
-
});
|
|
51
|
-
const ACCOUNT_SHAPE_INFO = {
|
|
52
|
-
address: TEST_ADDRESS,
|
|
53
|
-
currency,
|
|
54
|
-
derivationMode,
|
|
55
|
-
derivationPath,
|
|
56
|
-
index: 0,
|
|
57
|
-
};
|
|
58
|
-
describe("sync (devnet)", () => {
|
|
59
|
-
beforeAll(async () => {
|
|
60
|
-
config_1.default.setCoinConfig(() => ({
|
|
61
|
-
gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
|
|
62
|
-
useGateway: true,
|
|
63
|
-
networkType: "devnet",
|
|
64
|
-
status: {
|
|
65
|
-
type: "active",
|
|
66
|
-
},
|
|
67
|
-
}));
|
|
68
|
-
});
|
|
69
|
-
describe("getAccountShape", () => {
|
|
70
|
-
it("should fetch account shape for a valid address", async () => {
|
|
71
|
-
const result = await (0, sync_1.getAccountShape)(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
72
|
-
expect(result).toBeDefined();
|
|
73
|
-
expect(result.id).toBeDefined();
|
|
74
|
-
expect(result.xpub).toBe(TEST_ADDRESS.replace(/:/g, "_"));
|
|
75
|
-
expect(result.blockHeight).toBeGreaterThan(0);
|
|
76
|
-
expect(result.balance).toBeDefined();
|
|
77
|
-
expect(result.spendableBalance).toBeDefined();
|
|
78
|
-
expect(result.operations).toBeDefined();
|
|
79
|
-
expect(result.operationsCount).toBeGreaterThanOrEqual(0);
|
|
80
|
-
expect(result.balance).toBeInstanceOf(Object);
|
|
81
|
-
expect(result.balance?.toNumber).toBeDefined();
|
|
82
|
-
expect(result.spendableBalance).toBeInstanceOf(Object);
|
|
83
|
-
expect(result.spendableBalance?.toNumber).toBeDefined();
|
|
84
|
-
expect(result.spendableBalance?.toNumber()).toBeLessThanOrEqual(result.balance?.toNumber() || 0);
|
|
85
|
-
});
|
|
86
|
-
it("should handle address with colons correctly", async () => {
|
|
87
|
-
const result = await (0, sync_1.getAccountShape)(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
88
|
-
expect(result.xpub).toBe(TEST_ADDRESS.replace(/:/g, "_"));
|
|
89
|
-
});
|
|
90
|
-
it("should merge operations correctly with initial account", async () => {
|
|
91
|
-
const operations = [
|
|
92
|
-
{
|
|
93
|
-
id: "test-op-1",
|
|
94
|
-
hash: "test-hash-1",
|
|
95
|
-
accountId: "test-account",
|
|
96
|
-
type: "OUT",
|
|
97
|
-
value: new bignumber_js_1.default(1000000),
|
|
98
|
-
fee: new bignumber_js_1.default(100000),
|
|
99
|
-
blockHash: "block-hash-1",
|
|
100
|
-
blockHeight: 100,
|
|
101
|
-
senders: [TEST_ADDRESS],
|
|
102
|
-
recipients: ["recipient-1"],
|
|
103
|
-
date: new Date("2023-01-01"),
|
|
104
|
-
transactionSequenceNumber: 100,
|
|
105
|
-
extra: { uid: "uid-1" },
|
|
106
|
-
},
|
|
107
|
-
];
|
|
108
|
-
const result = await (0, sync_1.getAccountShape)({
|
|
109
|
-
...ACCOUNT_SHAPE_INFO,
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
111
|
-
initialAccount: { operations },
|
|
112
|
-
}, { paginationConfig: {} });
|
|
113
|
-
expect(result.operations).toBeDefined();
|
|
114
|
-
expect(result.operationsCount).toBeGreaterThanOrEqual(1);
|
|
115
|
-
const initialOp = result.operations?.find(op => op.id === "test-op-1");
|
|
116
|
-
expect(initialOp).toBeDefined();
|
|
117
|
-
});
|
|
118
|
-
it("should take locked balance into account when calculating spendable balance", async () => {
|
|
119
|
-
const mockGetBalance = jest.spyOn(gateway, "getBalance");
|
|
120
|
-
mockGetBalance.mockResolvedValue([
|
|
121
|
-
{
|
|
122
|
-
instrument_id: "Amulet",
|
|
123
|
-
amount: 1000000,
|
|
124
|
-
locked: true,
|
|
125
|
-
},
|
|
126
|
-
]);
|
|
127
|
-
const result = await (0, sync_1.getAccountShape)(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
128
|
-
expect(result.balance?.toNumber()).toBe(1000000);
|
|
129
|
-
expect(result.spendableBalance?.toNumber()).toBe(0);
|
|
130
|
-
mockGetBalance.mockRestore();
|
|
131
|
-
});
|
|
132
|
-
it("should call getOperations with correct cursor based with initial account", async () => {
|
|
133
|
-
const mockGetOperations = jest.spyOn(gateway, "getOperations");
|
|
134
|
-
const operation = {
|
|
135
|
-
id: "test-op-1",
|
|
136
|
-
hash: "test-hash-1",
|
|
137
|
-
accountId: "test-account",
|
|
138
|
-
type: "OUT",
|
|
139
|
-
value: new bignumber_js_1.default(1000000),
|
|
140
|
-
fee: new bignumber_js_1.default(100000),
|
|
141
|
-
blockHash: "block-hash-1",
|
|
142
|
-
blockHeight: 100,
|
|
143
|
-
senders: [TEST_ADDRESS],
|
|
144
|
-
recipients: ["recipient-1"],
|
|
145
|
-
date: new Date("2023-01-01"),
|
|
146
|
-
transactionSequenceNumber: 100,
|
|
147
|
-
extra: { uid: "uid-1" },
|
|
148
|
-
};
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
150
|
-
const initialAccount = { operations: [operation] };
|
|
151
|
-
const result = await (0, sync_1.getAccountShape)({
|
|
152
|
-
...ACCOUNT_SHAPE_INFO,
|
|
153
|
-
initialAccount,
|
|
154
|
-
}, { paginationConfig: {} });
|
|
155
|
-
expect(mockGetOperations).toHaveBeenCalledWith(TEST_ADDRESS, {
|
|
156
|
-
cursor: (operation.blockHeight || 0) + 1,
|
|
157
|
-
limit: 100,
|
|
158
|
-
});
|
|
159
|
-
expect(result.operations).toBeDefined();
|
|
160
|
-
expect(result.operationsCount).toBeGreaterThan(1);
|
|
161
|
-
});
|
|
162
|
-
it("should call getOperations with cursor 0 when no initial account", async () => {
|
|
163
|
-
const mockGetOperations = jest.spyOn(gateway, "getOperations");
|
|
164
|
-
const result = await (0, sync_1.getAccountShape)(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
165
|
-
expect(result.operations).toBeDefined();
|
|
166
|
-
expect(result.operationsCount).toBeGreaterThanOrEqual(1);
|
|
167
|
-
expect(mockGetOperations).toHaveBeenCalledWith(TEST_ADDRESS, {
|
|
168
|
-
cursor: 0,
|
|
169
|
-
limit: 100,
|
|
170
|
-
});
|
|
171
|
-
mockGetOperations.mockRestore();
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
//# sourceMappingURL=sync.integ.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync.integ.test.js","sourceRoot":"","sources":["../../src/bridge/sync.integ.test.ts"],"names":[],"mappings":";;;;;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|
2
|
-
export declare function assignToAccountRaw(account: Account, accountRaw: AccountRaw): void;
|
|
3
|
-
export declare function assignFromAccountRaw(accountRaw: AccountRaw, account: Account): void;
|
|
4
|
-
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../src/bridge/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAqBhE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAMjF;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAMnF"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function toResourcesRaw(r) {
|
|
2
|
-
const { partyId } = r;
|
|
3
|
-
return {
|
|
4
|
-
partyId,
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
function fromResourcesRaw(r) {
|
|
8
|
-
const { partyId } = r;
|
|
9
|
-
return {
|
|
10
|
-
partyId,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export function assignToAccountRaw(account, accountRaw) {
|
|
14
|
-
const cantonAccount = account;
|
|
15
|
-
const cantonAccountRaw = accountRaw;
|
|
16
|
-
if (cantonAccount.cantonResources) {
|
|
17
|
-
cantonAccountRaw.cantonResources = toResourcesRaw(cantonAccount.cantonResources);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function assignFromAccountRaw(accountRaw, account) {
|
|
21
|
-
const cantonResourcesRaw = accountRaw.cantonResources;
|
|
22
|
-
const cantonAccount = account;
|
|
23
|
-
if (cantonResourcesRaw) {
|
|
24
|
-
cantonAccount.cantonResources = fromResourcesRaw(cantonResourcesRaw);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=serialization.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["../../src/bridge/serialization.ts"],"names":[],"mappings":"AAQA,SAAS,cAAc,CAAC,CAAkB;IACxC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACtB,OAAO;QACL,OAAO;KACR,CAAC;AACJ,CAAC;AACD,SAAS,gBAAgB,CAAC,CAAqB;IAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACtB,OAAO;QACL,OAAO;KACR,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAgB,EAAE,UAAsB;IACzE,MAAM,aAAa,GAAG,OAAwB,CAAC;IAC/C,MAAM,gBAAgB,GAAG,UAA8B,CAAC;IACxD,IAAI,aAAa,CAAC,eAAe,EAAE,CAAC;QAClC,gBAAgB,CAAC,eAAe,GAAG,cAAc,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IACnF,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAsB,EAAE,OAAgB;IAC3E,MAAM,kBAAkB,GAAI,UAA+B,CAAC,eAAe,CAAC;IAC5E,MAAM,aAAa,GAAG,OAAwB,CAAC;IAC/C,IAAI,kBAAkB,EAAE,CAAC;QACvB,aAAa,CAAC,eAAe,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;IACvE,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync.integ.test.d.ts","sourceRoot":"","sources":["../../src/bridge/sync.integ.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import BigNumber from "bignumber.js";
|
|
2
|
-
import { getDerivationModesForCurrency, getDerivationScheme, runDerivationScheme, } from "@ledgerhq/coin-framework/derivation";
|
|
3
|
-
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
4
|
-
import coinConfig from "../config";
|
|
5
|
-
import * as gateway from "../network/gateway";
|
|
6
|
-
import { getAccountShape } from "./sync";
|
|
7
|
-
const TEST_ADDRESS = "b6400f93ea1c74aea86be39b0ccc846fc5de01f12b2ad0d7c31848d6fb6eb6d9::1220c81315e2bf2524a9141bcc6cbf19b61c151e0dcaa95343c0ccf53aed7415c4ec";
|
|
8
|
-
const currency = getCryptoCurrencyById("canton_network");
|
|
9
|
-
const derivationMode = getDerivationModesForCurrency(currency)[0];
|
|
10
|
-
const derivationPath = runDerivationScheme(getDerivationScheme({ derivationMode, currency }), currency, {
|
|
11
|
-
account: 0,
|
|
12
|
-
});
|
|
13
|
-
const ACCOUNT_SHAPE_INFO = {
|
|
14
|
-
address: TEST_ADDRESS,
|
|
15
|
-
currency,
|
|
16
|
-
derivationMode,
|
|
17
|
-
derivationPath,
|
|
18
|
-
index: 0,
|
|
19
|
-
};
|
|
20
|
-
describe("sync (devnet)", () => {
|
|
21
|
-
beforeAll(async () => {
|
|
22
|
-
coinConfig.setCoinConfig(() => ({
|
|
23
|
-
gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
|
|
24
|
-
useGateway: true,
|
|
25
|
-
networkType: "devnet",
|
|
26
|
-
status: {
|
|
27
|
-
type: "active",
|
|
28
|
-
},
|
|
29
|
-
}));
|
|
30
|
-
});
|
|
31
|
-
describe("getAccountShape", () => {
|
|
32
|
-
it("should fetch account shape for a valid address", async () => {
|
|
33
|
-
const result = await getAccountShape(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
34
|
-
expect(result).toBeDefined();
|
|
35
|
-
expect(result.id).toBeDefined();
|
|
36
|
-
expect(result.xpub).toBe(TEST_ADDRESS.replace(/:/g, "_"));
|
|
37
|
-
expect(result.blockHeight).toBeGreaterThan(0);
|
|
38
|
-
expect(result.balance).toBeDefined();
|
|
39
|
-
expect(result.spendableBalance).toBeDefined();
|
|
40
|
-
expect(result.operations).toBeDefined();
|
|
41
|
-
expect(result.operationsCount).toBeGreaterThanOrEqual(0);
|
|
42
|
-
expect(result.balance).toBeInstanceOf(Object);
|
|
43
|
-
expect(result.balance?.toNumber).toBeDefined();
|
|
44
|
-
expect(result.spendableBalance).toBeInstanceOf(Object);
|
|
45
|
-
expect(result.spendableBalance?.toNumber).toBeDefined();
|
|
46
|
-
expect(result.spendableBalance?.toNumber()).toBeLessThanOrEqual(result.balance?.toNumber() || 0);
|
|
47
|
-
});
|
|
48
|
-
it("should handle address with colons correctly", async () => {
|
|
49
|
-
const result = await getAccountShape(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
50
|
-
expect(result.xpub).toBe(TEST_ADDRESS.replace(/:/g, "_"));
|
|
51
|
-
});
|
|
52
|
-
it("should merge operations correctly with initial account", async () => {
|
|
53
|
-
const operations = [
|
|
54
|
-
{
|
|
55
|
-
id: "test-op-1",
|
|
56
|
-
hash: "test-hash-1",
|
|
57
|
-
accountId: "test-account",
|
|
58
|
-
type: "OUT",
|
|
59
|
-
value: new BigNumber(1000000),
|
|
60
|
-
fee: new BigNumber(100000),
|
|
61
|
-
blockHash: "block-hash-1",
|
|
62
|
-
blockHeight: 100,
|
|
63
|
-
senders: [TEST_ADDRESS],
|
|
64
|
-
recipients: ["recipient-1"],
|
|
65
|
-
date: new Date("2023-01-01"),
|
|
66
|
-
transactionSequenceNumber: 100,
|
|
67
|
-
extra: { uid: "uid-1" },
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
const result = await getAccountShape({
|
|
71
|
-
...ACCOUNT_SHAPE_INFO,
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
73
|
-
initialAccount: { operations },
|
|
74
|
-
}, { paginationConfig: {} });
|
|
75
|
-
expect(result.operations).toBeDefined();
|
|
76
|
-
expect(result.operationsCount).toBeGreaterThanOrEqual(1);
|
|
77
|
-
const initialOp = result.operations?.find(op => op.id === "test-op-1");
|
|
78
|
-
expect(initialOp).toBeDefined();
|
|
79
|
-
});
|
|
80
|
-
it("should take locked balance into account when calculating spendable balance", async () => {
|
|
81
|
-
const mockGetBalance = jest.spyOn(gateway, "getBalance");
|
|
82
|
-
mockGetBalance.mockResolvedValue([
|
|
83
|
-
{
|
|
84
|
-
instrument_id: "Amulet",
|
|
85
|
-
amount: 1000000,
|
|
86
|
-
locked: true,
|
|
87
|
-
},
|
|
88
|
-
]);
|
|
89
|
-
const result = await getAccountShape(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
90
|
-
expect(result.balance?.toNumber()).toBe(1000000);
|
|
91
|
-
expect(result.spendableBalance?.toNumber()).toBe(0);
|
|
92
|
-
mockGetBalance.mockRestore();
|
|
93
|
-
});
|
|
94
|
-
it("should call getOperations with correct cursor based with initial account", async () => {
|
|
95
|
-
const mockGetOperations = jest.spyOn(gateway, "getOperations");
|
|
96
|
-
const operation = {
|
|
97
|
-
id: "test-op-1",
|
|
98
|
-
hash: "test-hash-1",
|
|
99
|
-
accountId: "test-account",
|
|
100
|
-
type: "OUT",
|
|
101
|
-
value: new BigNumber(1000000),
|
|
102
|
-
fee: new BigNumber(100000),
|
|
103
|
-
blockHash: "block-hash-1",
|
|
104
|
-
blockHeight: 100,
|
|
105
|
-
senders: [TEST_ADDRESS],
|
|
106
|
-
recipients: ["recipient-1"],
|
|
107
|
-
date: new Date("2023-01-01"),
|
|
108
|
-
transactionSequenceNumber: 100,
|
|
109
|
-
extra: { uid: "uid-1" },
|
|
110
|
-
};
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
112
|
-
const initialAccount = { operations: [operation] };
|
|
113
|
-
const result = await getAccountShape({
|
|
114
|
-
...ACCOUNT_SHAPE_INFO,
|
|
115
|
-
initialAccount,
|
|
116
|
-
}, { paginationConfig: {} });
|
|
117
|
-
expect(mockGetOperations).toHaveBeenCalledWith(TEST_ADDRESS, {
|
|
118
|
-
cursor: (operation.blockHeight || 0) + 1,
|
|
119
|
-
limit: 100,
|
|
120
|
-
});
|
|
121
|
-
expect(result.operations).toBeDefined();
|
|
122
|
-
expect(result.operationsCount).toBeGreaterThan(1);
|
|
123
|
-
});
|
|
124
|
-
it("should call getOperations with cursor 0 when no initial account", async () => {
|
|
125
|
-
const mockGetOperations = jest.spyOn(gateway, "getOperations");
|
|
126
|
-
const result = await getAccountShape(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
127
|
-
expect(result.operations).toBeDefined();
|
|
128
|
-
expect(result.operationsCount).toBeGreaterThanOrEqual(1);
|
|
129
|
-
expect(mockGetOperations).toHaveBeenCalledWith(TEST_ADDRESS, {
|
|
130
|
-
cursor: 0,
|
|
131
|
-
limit: 100,
|
|
132
|
-
});
|
|
133
|
-
mockGetOperations.mockRestore();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
//# sourceMappingURL=sync.integ.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync.integ.test.js","sourceRoot":"","sources":["../../src/bridge/sync.integ.test.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,6BAA6B,EAC7B,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,UAAU,MAAM,WAAW,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,YAAY,GAChB,wIAAwI,CAAC;AAC3I,MAAM,QAAQ,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;AACzD,MAAM,cAAc,GAAG,6BAA6B,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,MAAM,cAAc,GAAG,mBAAmB,CACxC,mBAAmB,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,EACjD,QAAQ,EACR;IACE,OAAO,E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CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iEAAiE,EAAE,KAAK,IAAI,EAAE;YAC/E,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;YAE/D,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,kBAAkB,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,CAAC,CAAC;YAEnF,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;YACxC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;YAEzD,MAAM,CAAC,iBAAiB,CAAC,CAAC,oBAAoB,CAAC,YAAY,EAAE;gBAC3D,MAAM,EAAE,CAAC;gBACT,KAAK,EAAE,GAAG;aACX,CAAC,CAAC;YAEH,iBAAiB,CAAC,WAAW,EAAE,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Account, AccountRaw } from "@ledgerhq/types-live";
|
|
2
|
-
import type {
|
|
3
|
-
CantonAccount,
|
|
4
|
-
CantonAccountRaw,
|
|
5
|
-
CantonResources,
|
|
6
|
-
CantonResourcesRaw,
|
|
7
|
-
} from "../types";
|
|
8
|
-
|
|
9
|
-
function toResourcesRaw(r: CantonResources): CantonResourcesRaw {
|
|
10
|
-
const { partyId } = r;
|
|
11
|
-
return {
|
|
12
|
-
partyId,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function fromResourcesRaw(r: CantonResourcesRaw): CantonResources {
|
|
16
|
-
const { partyId } = r;
|
|
17
|
-
return {
|
|
18
|
-
partyId,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function assignToAccountRaw(account: Account, accountRaw: AccountRaw): void {
|
|
23
|
-
const cantonAccount = account as CantonAccount;
|
|
24
|
-
const cantonAccountRaw = accountRaw as CantonAccountRaw;
|
|
25
|
-
if (cantonAccount.cantonResources) {
|
|
26
|
-
cantonAccountRaw.cantonResources = toResourcesRaw(cantonAccount.cantonResources);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function assignFromAccountRaw(accountRaw: AccountRaw, account: Account): void {
|
|
31
|
-
const cantonResourcesRaw = (accountRaw as CantonAccountRaw).cantonResources;
|
|
32
|
-
const cantonAccount = account as CantonAccount;
|
|
33
|
-
if (cantonResourcesRaw) {
|
|
34
|
-
cantonAccount.cantonResources = fromResourcesRaw(cantonResourcesRaw);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import BigNumber from "bignumber.js";
|
|
2
|
-
import { AccountShapeInfo } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
3
|
-
import {
|
|
4
|
-
getDerivationModesForCurrency,
|
|
5
|
-
getDerivationScheme,
|
|
6
|
-
runDerivationScheme,
|
|
7
|
-
} from "@ledgerhq/coin-framework/derivation";
|
|
8
|
-
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
9
|
-
import { Account, Operation } from "@ledgerhq/types-live";
|
|
10
|
-
import coinConfig from "../config";
|
|
11
|
-
import * as gateway from "../network/gateway";
|
|
12
|
-
import { getAccountShape } from "./sync";
|
|
13
|
-
|
|
14
|
-
const TEST_ADDRESS =
|
|
15
|
-
"b6400f93ea1c74aea86be39b0ccc846fc5de01f12b2ad0d7c31848d6fb6eb6d9::1220c81315e2bf2524a9141bcc6cbf19b61c151e0dcaa95343c0ccf53aed7415c4ec";
|
|
16
|
-
const currency = getCryptoCurrencyById("canton_network");
|
|
17
|
-
const derivationMode = getDerivationModesForCurrency(currency)[0];
|
|
18
|
-
const derivationPath = runDerivationScheme(
|
|
19
|
-
getDerivationScheme({ derivationMode, currency }),
|
|
20
|
-
currency,
|
|
21
|
-
{
|
|
22
|
-
account: 0,
|
|
23
|
-
},
|
|
24
|
-
);
|
|
25
|
-
const ACCOUNT_SHAPE_INFO: AccountShapeInfo = {
|
|
26
|
-
address: TEST_ADDRESS,
|
|
27
|
-
currency,
|
|
28
|
-
derivationMode,
|
|
29
|
-
derivationPath,
|
|
30
|
-
index: 0,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
describe("sync (devnet)", () => {
|
|
34
|
-
beforeAll(async () => {
|
|
35
|
-
coinConfig.setCoinConfig(() => ({
|
|
36
|
-
gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
|
|
37
|
-
useGateway: true,
|
|
38
|
-
networkType: "devnet",
|
|
39
|
-
status: {
|
|
40
|
-
type: "active",
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("getAccountShape", () => {
|
|
46
|
-
it("should fetch account shape for a valid address", async () => {
|
|
47
|
-
const result = await getAccountShape(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
48
|
-
|
|
49
|
-
expect(result).toBeDefined();
|
|
50
|
-
expect(result.id).toBeDefined();
|
|
51
|
-
expect(result.xpub).toBe(TEST_ADDRESS.replace(/:/g, "_"));
|
|
52
|
-
expect(result.blockHeight).toBeGreaterThan(0);
|
|
53
|
-
expect(result.balance).toBeDefined();
|
|
54
|
-
expect(result.spendableBalance).toBeDefined();
|
|
55
|
-
expect(result.operations).toBeDefined();
|
|
56
|
-
expect(result.operationsCount).toBeGreaterThanOrEqual(0);
|
|
57
|
-
|
|
58
|
-
expect(result.balance).toBeInstanceOf(Object);
|
|
59
|
-
expect(result.balance?.toNumber).toBeDefined();
|
|
60
|
-
expect(result.spendableBalance).toBeInstanceOf(Object);
|
|
61
|
-
expect(result.spendableBalance?.toNumber).toBeDefined();
|
|
62
|
-
|
|
63
|
-
expect(result.spendableBalance?.toNumber()).toBeLessThanOrEqual(
|
|
64
|
-
result.balance?.toNumber() || 0,
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("should handle address with colons correctly", async () => {
|
|
69
|
-
const result = await getAccountShape(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
70
|
-
|
|
71
|
-
expect(result.xpub).toBe(TEST_ADDRESS.replace(/:/g, "_"));
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("should merge operations correctly with initial account", async () => {
|
|
75
|
-
const operations: Operation[] = [
|
|
76
|
-
{
|
|
77
|
-
id: "test-op-1",
|
|
78
|
-
hash: "test-hash-1",
|
|
79
|
-
accountId: "test-account",
|
|
80
|
-
type: "OUT" as const,
|
|
81
|
-
value: new BigNumber(1000000),
|
|
82
|
-
fee: new BigNumber(100000),
|
|
83
|
-
blockHash: "block-hash-1",
|
|
84
|
-
blockHeight: 100,
|
|
85
|
-
senders: [TEST_ADDRESS],
|
|
86
|
-
recipients: ["recipient-1"],
|
|
87
|
-
date: new Date("2023-01-01"),
|
|
88
|
-
transactionSequenceNumber: 100,
|
|
89
|
-
extra: { uid: "uid-1" },
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
const result = await getAccountShape(
|
|
94
|
-
{
|
|
95
|
-
...ACCOUNT_SHAPE_INFO,
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
97
|
-
initialAccount: { operations } as Account,
|
|
98
|
-
},
|
|
99
|
-
{ paginationConfig: {} },
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
expect(result.operations).toBeDefined();
|
|
103
|
-
expect(result.operationsCount).toBeGreaterThanOrEqual(1);
|
|
104
|
-
const initialOp = result.operations?.find(op => op.id === "test-op-1");
|
|
105
|
-
expect(initialOp).toBeDefined();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should take locked balance into account when calculating spendable balance", async () => {
|
|
109
|
-
const mockGetBalance = jest.spyOn(gateway, "getBalance");
|
|
110
|
-
|
|
111
|
-
mockGetBalance.mockResolvedValue([
|
|
112
|
-
{
|
|
113
|
-
instrument_id: "Amulet",
|
|
114
|
-
amount: 1000000,
|
|
115
|
-
locked: true,
|
|
116
|
-
},
|
|
117
|
-
]);
|
|
118
|
-
|
|
119
|
-
const result = await getAccountShape(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
120
|
-
|
|
121
|
-
expect(result.balance?.toNumber()).toBe(1000000);
|
|
122
|
-
expect(result.spendableBalance?.toNumber()).toBe(0);
|
|
123
|
-
|
|
124
|
-
mockGetBalance.mockRestore();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("should call getOperations with correct cursor based with initial account", async () => {
|
|
128
|
-
const mockGetOperations = jest.spyOn(gateway, "getOperations");
|
|
129
|
-
const operation: Operation = {
|
|
130
|
-
id: "test-op-1",
|
|
131
|
-
hash: "test-hash-1",
|
|
132
|
-
accountId: "test-account",
|
|
133
|
-
type: "OUT" as const,
|
|
134
|
-
value: new BigNumber(1000000),
|
|
135
|
-
fee: new BigNumber(100000),
|
|
136
|
-
blockHash: "block-hash-1",
|
|
137
|
-
blockHeight: 100,
|
|
138
|
-
senders: [TEST_ADDRESS],
|
|
139
|
-
recipients: ["recipient-1"],
|
|
140
|
-
date: new Date("2023-01-01"),
|
|
141
|
-
transactionSequenceNumber: 100,
|
|
142
|
-
extra: { uid: "uid-1" },
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
146
|
-
const initialAccount = { operations: [operation] } as Account;
|
|
147
|
-
|
|
148
|
-
const result = await getAccountShape(
|
|
149
|
-
{
|
|
150
|
-
...ACCOUNT_SHAPE_INFO,
|
|
151
|
-
initialAccount,
|
|
152
|
-
},
|
|
153
|
-
{ paginationConfig: {} },
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
expect(mockGetOperations).toHaveBeenCalledWith(TEST_ADDRESS, {
|
|
157
|
-
cursor: (operation.blockHeight || 0) + 1,
|
|
158
|
-
limit: 100,
|
|
159
|
-
});
|
|
160
|
-
expect(result.operations).toBeDefined();
|
|
161
|
-
expect(result.operationsCount).toBeGreaterThan(1);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("should call getOperations with cursor 0 when no initial account", async () => {
|
|
165
|
-
const mockGetOperations = jest.spyOn(gateway, "getOperations");
|
|
166
|
-
|
|
167
|
-
const result = await getAccountShape(ACCOUNT_SHAPE_INFO, { paginationConfig: {} });
|
|
168
|
-
|
|
169
|
-
expect(result.operations).toBeDefined();
|
|
170
|
-
expect(result.operationsCount).toBeGreaterThanOrEqual(1);
|
|
171
|
-
|
|
172
|
-
expect(mockGetOperations).toHaveBeenCalledWith(TEST_ADDRESS, {
|
|
173
|
-
cursor: 0,
|
|
174
|
-
limit: 100,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
mockGetOperations.mockRestore();
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|