@ledgerhq/coin-celo
Version:
490 lines • 18.1 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const fixtures_1 = require("../../bridge/fixtures");
const logic_1 = require("../../logic");
jest.useFakeTimers().setSystemTime(new Date("2020-01-01"));
describe("logic", () => {
it("availablePendingWithdrawals", () => {
const result = (0, logic_1.availablePendingWithdrawals)({
...fixtures_1.accountFixture,
celoResources: {
...fixtures_1.accountFixture.celoResources,
pendingWithdrawals: [
{
value: (0, bignumber_js_1.default)(123123123),
time: (0, bignumber_js_1.default)(31231),
index: 0,
},
{
value: (0, bignumber_js_1.default)(123123123),
time: (0, bignumber_js_1.default)(23214451),
index: 0,
},
{
value: (0, bignumber_js_1.default)(123123123),
time: (0, bignumber_js_1.default)(1577836900000),
index: 0,
},
],
},
});
expect(result).toHaveLength(2);
});
it("withdrawableBalance", () => {
const account = {
...fixtures_1.accountFixture,
celoResources: {
...fixtures_1.accountFixture.celoResources,
pendingWithdrawals: [
{
value: (0, bignumber_js_1.default)(123123123),
time: (0, bignumber_js_1.default)(31231),
index: 0,
},
{
value: (0, bignumber_js_1.default)(123123123),
time: (0, bignumber_js_1.default)(23214451),
index: 0,
},
{
value: (0, bignumber_js_1.default)(123123123),
time: (0, bignumber_js_1.default)(1577836900000),
index: 0,
},
],
},
};
expect((0, logic_1.withdrawableBalance)(account)).toEqual((0, bignumber_js_1.default)(246246246));
expect((0, logic_1.hasWithdrawableBalance)(account)).toBeTruthy();
});
it("isDefaultValidatorGroupAddress", () => {
expect((0, logic_1.isDefaultValidatorGroupAddress)("other_address")).toBeFalsy();
expect((0, logic_1.isDefaultValidatorGroupAddress)((0, logic_1.defaultValidatorGroupAddress)())).toBeTruthy();
expect((0, logic_1.isDefaultValidatorGroup)({
address: "validator_address",
name: "validator1",
votes: (0, bignumber_js_1.default)(8484848),
})).toBeFalsy();
expect((0, logic_1.isDefaultValidatorGroup)({
address: (0, logic_1.defaultValidatorGroupAddress)(),
name: "validator1",
votes: (0, bignumber_js_1.default)(8484848),
})).toBeTruthy();
});
it("activatableVotes", () => {
const account = {
...fixtures_1.accountFixture,
celoResources: {
...fixtures_1.accountFixture.celoResources,
votes: [
{
validatorGroup: "1",
amount: (0, bignumber_js_1.default)(123),
activatable: true,
revokable: false,
type: "active",
index: 0,
},
{
validatorGroup: "2",
amount: (0, bignumber_js_1.default)(123213),
activatable: false,
revokable: true,
type: "pending",
index: 0,
},
{
validatorGroup: "3",
amount: (0, bignumber_js_1.default)(1232223),
activatable: true,
revokable: false,
type: "active",
index: 0,
},
],
},
};
const result = (0, logic_1.activatableVotes)(account);
expect(result).toMatchObject([
{
validatorGroup: "1",
amount: (0, bignumber_js_1.default)(123),
activatable: true,
revokable: false,
type: "active",
index: 0,
},
{
validatorGroup: "3",
amount: (0, bignumber_js_1.default)(1232223),
activatable: true,
revokable: false,
type: "active",
index: 0,
},
]);
expect((0, logic_1.hasActivatableVotes)(account)).toBeTruthy();
expect((0, logic_1.revokableVotes)(account)).toMatchObject([
{
validatorGroup: "2",
amount: (0, bignumber_js_1.default)(123213),
activatable: false,
revokable: true,
type: "pending",
index: 0,
},
]);
expect((0, logic_1.hasRevokableVotes)(account)).toBeTruthy();
});
it("getVote", () => {
const account = {
...fixtures_1.accountFixture,
celoResources: {
...fixtures_1.accountFixture.celoResources,
votes: [
{
validatorGroup: "1",
amount: (0, bignumber_js_1.default)(123),
activatable: true,
revokable: false,
type: "active",
index: 0,
},
{
validatorGroup: "2",
amount: (0, bignumber_js_1.default)(123213),
activatable: false,
revokable: true,
type: "pending",
index: 0,
},
{
validatorGroup: "3",
amount: (0, bignumber_js_1.default)(1232223),
activatable: true,
revokable: false,
type: "active",
index: 0,
},
],
},
};
const result = (0, logic_1.getVote)(account, "2", 0);
expect(result).toMatchObject({
validatorGroup: "2",
amount: (0, bignumber_js_1.default)(123213),
activatable: false,
revokable: true,
type: "pending",
index: 0,
});
});
it("voteStatus", () => {
expect((0, logic_1.voteStatus)({
validatorGroup: "2",
amount: (0, bignumber_js_1.default)(123213),
activatable: true,
revokable: true,
type: "pending",
index: 0,
})).toEqual("awaitingActivation");
expect((0, logic_1.voteStatus)({
validatorGroup: "2",
amount: (0, bignumber_js_1.default)(123213),
activatable: false,
revokable: true,
type: "pending",
index: 0,
})).toEqual("pending");
});
it("fallbackValidatorGroup", () => {
expect((0, logic_1.fallbackValidatorGroup)("address")).toMatchObject({
address: "address",
name: "address",
votes: (0, bignumber_js_1.default)(0),
});
});
it("isAccountRegistrationPending", () => {
const account = {
...fixtures_1.accountFixture,
pendingOperations: [
{
id: "pendingOperation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "REGISTER",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(1),
hash: "hash",
extra: "extra",
},
],
celoResources: {
...fixtures_1.accountFixture.celoResources,
registrationStatus: false,
},
};
expect((0, logic_1.isAccountRegistrationPending)(account)).toBeTruthy();
});
it("getPendingStakingOperationAmounts", () => {
const account = {
...fixtures_1.accountFixture,
pendingOperations: [
{
id: "pendingOperation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "VOTE",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(2),
hash: "hash",
extra: "extra",
},
{
id: "pendingOperation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "VOTE",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(10),
hash: "hash",
extra: "extra",
},
{
id: "pendingOperation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "LOCK",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(30),
hash: "hash",
extra: "extra",
},
{
id: "pendingOperation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "REGISTER",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(30),
hash: "hash",
extra: "extra",
},
],
celoResources: {
...fixtures_1.accountFixture.celoResources,
registrationStatus: false,
},
};
const result = (0, logic_1.getPendingStakingOperationAmounts)(account);
expect(result).toMatchObject({
vote: (0, bignumber_js_1.default)(12),
lock: (0, bignumber_js_1.default)(30),
});
});
it("getPendingStakingOperationAmounts", () => {
const account = {
...fixtures_1.accountFixture,
pendingOperations: [
{
id: "pendingOperation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "VOTE",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(2),
hash: "hash",
extra: "extra",
},
{
id: "pendingOperation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "VOTE",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(10),
hash: "hash",
extra: "extra",
},
{
id: "pendingOperation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "LOCK",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(30),
hash: "hash",
extra: "extra",
},
{
id: "pendingOperation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "REGISTER",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(30),
hash: "hash",
extra: "extra",
},
],
celoResources: {
...fixtures_1.accountFixture.celoResources,
registrationStatus: false,
},
operations: [
{
id: "operation1",
accountId: fixtures_1.accountFixture.id,
blockHash: "block_hash",
blockHeight: 1,
date: new Date(),
type: "LOCK",
senders: [],
recipients: [],
fee: (0, bignumber_js_1.default)(0),
value: (0, bignumber_js_1.default)(1),
hash: "hash",
extra: "extra",
},
],
operationsCount: 1,
};
const result = (0, logic_1.getPendingStakingOperationAmounts)(account);
expect(result).toMatchObject({
vote: (0, bignumber_js_1.default)(0),
lock: (0, bignumber_js_1.default)(0),
});
});
it("getValidatorGroupsWithVotes", () => {
const result = (0, logic_1.getValidatorGroupsWithVotes)([
{
address: "validator1",
name: "validator1",
votes: (0, bignumber_js_1.default)(3),
},
{
address: "validator2",
name: "validator2",
votes: (0, bignumber_js_1.default)(4),
},
{
address: "validator3",
name: "validator3",
votes: (0, bignumber_js_1.default)(0),
},
], [
{
validatorGroup: "validator1",
amount: (0, bignumber_js_1.default)(1),
activatable: true,
revokable: true,
type: "active",
index: 0,
},
{
validatorGroup: "validator2",
amount: (0, bignumber_js_1.default)(2),
activatable: true,
revokable: true,
type: "active",
index: 0,
},
]);
expect(result).toMatchObject([
{
address: "validator1",
name: "validator1",
votes: (0, bignumber_js_1.default)(3),
},
{
address: "validator2",
name: "validator2",
votes: (0, bignumber_js_1.default)(4),
},
]);
});
it("getValidatorGroupsWithoutVotes", () => {
const result = (0, logic_1.getValidatorGroupsWithoutVotes)([
{
address: "validator1",
name: "validator1",
votes: (0, bignumber_js_1.default)(3),
},
{
address: "validator2",
name: "validator2",
votes: (0, bignumber_js_1.default)(4),
},
{
address: "validator3",
name: "validator3",
votes: (0, bignumber_js_1.default)(0),
},
], [
{
validatorGroup: "validator1",
amount: (0, bignumber_js_1.default)(1),
activatable: true,
revokable: true,
type: "active",
index: 0,
},
{
validatorGroup: "validator2",
amount: (0, bignumber_js_1.default)(2),
activatable: true,
revokable: true,
type: "active",
index: 0,
},
]);
expect(result).toMatchObject([
{
address: "validator3",
name: "validator3",
votes: (0, bignumber_js_1.default)(0),
},
]);
});
});
//# sourceMappingURL=logic.test.js.map