Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-moles-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/wallet-api-core": patch
---

chore: align Tron types with Ledger Wallet
2 changes: 1 addition & 1 deletion packages/core/src/families/tron/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type TronTransaction = TransactionCommon & {
mode: TronOperationMode;
resource?: TronResource;
duration?: number;
votes?: TronVote[];
votes: TronVote[];
};

export type RawTronTransaction = z.infer<typeof schemaRawTronTransaction>;
2 changes: 1 addition & 1 deletion packages/core/src/families/tron/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export const schemaRawTronTransaction = schemaTransactionCommon.extend({
mode: schemaTronOperationMode,
resource: schemaTronResource.optional(),
duration: z.number().optional(),
votes: z.array(schemaTronVotes).optional(),
votes: z.array(schemaTronVotes).default([]),
});
55 changes: 55 additions & 0 deletions packages/core/tests/serializers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
RawVechainTransaction,
RawHederaTransaction,
HederaTransaction,
schemaRawTransaction,
} from "../src";

const date = new Date();
Expand Down Expand Up @@ -633,6 +634,7 @@ describe("serializers.ts", () => {
duration: 5,
amount: new BigNumber(100),
recipient: "recipient",
votes: [],
};
const serializedTransaction = serializeTransaction(transaction);

Expand All @@ -643,6 +645,7 @@ describe("serializers.ts", () => {
duration: 5,
amount: "100",
recipient: "recipient",
votes: [],
});
});

Expand All @@ -652,6 +655,7 @@ describe("serializers.ts", () => {
mode: "send",
amount: new BigNumber(100),
recipient: "recipient",
votes: [],
};
const serializedTransaction = serializeTransaction(transaction);

Expand All @@ -662,6 +666,7 @@ describe("serializers.ts", () => {
duration: undefined,
amount: "100",
recipient: "recipient",
votes: [],
});
});

Expand All @@ -676,6 +681,7 @@ describe("serializers.ts", () => {
{ address: "recipient2", voteCount: 50 },
],
};

const serializedTransaction = serializeTransaction(transaction);

expect(serializedTransaction).toEqual({
Expand Down Expand Up @@ -1563,6 +1569,7 @@ describe("serializers.ts", () => {
duration: 5,
amount: "100",
recipient: "recipient",
votes: [],
};

const transaction = deserializeTransaction(serializedTransaction);
Expand All @@ -1574,6 +1581,7 @@ describe("serializers.ts", () => {
duration: 5,
amount: new BigNumber(100),
recipient: "recipient",
votes: [],
});
});

Expand All @@ -1583,6 +1591,7 @@ describe("serializers.ts", () => {
mode: "send",
amount: "100",
recipient: "recipient",
votes: [],
};

const transaction = deserializeTransaction(serializedTransaction);
Expand All @@ -1594,6 +1603,52 @@ describe("serializers.ts", () => {
duration: undefined,
amount: new BigNumber(100),
recipient: "recipient",
votes: [],
});
});

it("should default missing votes to [] when parsing a raw tron transaction", () => {
const parsed = schemaRawTransaction.parse({
family,
mode: "send",
amount: "100",
recipient: "recipient",
});

expect(parsed).toEqual({
family,
mode: "send",
amount: "100",
recipient: "recipient",
votes: [],
});
});

it("should succeed to deserialize a tron transaction with votes", () => {
const serializedTransaction: RawTronTransaction = {
family,
mode: "vote",
amount: "100",
recipient: "recipient",
votes: [
{ address: "recipient", voteCount: 50 },
{ address: "recipient2", voteCount: 50 },
],
};

const transaction = deserializeTransaction(serializedTransaction);

expect(transaction).toEqual({
family,
mode: "vote",
resource: undefined,
duration: undefined,
amount: new BigNumber(100),
recipient: "recipient",
votes: [
{ address: "recipient", voteCount: 50 },
{ address: "recipient2", voteCount: 50 },
],
});
});
});
Expand Down
Loading