-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsummonWallet.test.ts
More file actions
90 lines (79 loc) · 4.04 KB
/
summonWallet.test.ts
File metadata and controls
90 lines (79 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { buildWallet } from "../utils/common";
import { Wallet as DbWallet } from "@prisma/client";
import { RawImportBodies } from "../types/wallet";
describe("Summon Wallet Capabilities", () => {
const network = 0; // Testnet
const mockSummonWallet: DbWallet & { rawImportBodies: RawImportBodies } = {
id: "test-summon-uuid",
name: "Test Summon Wallet",
description: "A test summon wallet",
address: "addr_test1wpnlxv2xv988tvv9z06m6pax76r98slymr6uzy958tclv6sgp98k8",
type: "atLeast",
numRequiredSigners: 2,
signersAddresses: ["addr_test1vpu5vl76u73su6p0657cw6q0657cw6q0657cw6q0657cw6q0657cw"],
signersStakeKeys: [],
signersDRepKeys: [],
scriptCbor: "8201828200581caf000000000000000000000000000000000000000000000000000000008200581cb0000000000000000000000000000000000000000000000000000000",
isArchived: false,
createdAt: new Date(),
updatedAt: new Date(),
profileImageIpfsUrl: null,
stakeCredentialHash: null,
dRepId: "",
rawImportBodies: {
multisig: {
address: "addr_test1wpnlxv2xv988tvv9z06m6pax76r98slymr6uzy958tclv6sgp98k8",
payment_script: "8200581c00000000000000000000000000000000000000000000000000000000",
stake_script: "8200581c11111111111111111111111111111111111111111111111111111111",
}
}
} as any;
it("should correctly populate capabilities for a Summon wallet with staking", () => {
const wallet = buildWallet(mockSummonWallet, network);
expect(wallet.capabilities).toBeDefined();
expect(wallet.capabilities!.canStake).toBe(true);
expect(wallet.capabilities!.canVote).toBe(false);
expect(wallet.capabilities!.address).toBe(mockSummonWallet.rawImportBodies.multisig!.address);
expect(wallet.capabilities!.stakeAddress).toBeDefined();
expect(wallet.capabilities!.stakeAddress).toMatch(/^stake_test/);
});
it("should correctly populate capabilities for a Summon wallet without staking", () => {
const mockNoStake = {
...mockSummonWallet,
rawImportBodies: {
multisig: {
...mockSummonWallet.rawImportBodies.multisig,
stake_script: undefined
}
}
};
const wallet = buildWallet(mockNoStake, network);
expect(wallet.capabilities!.canStake).toBe(false);
expect(wallet.capabilities!.stakeAddress).toBeUndefined();
});
it("should correctly handle Summon wallets with unordered CBOR lists", () => {
// Swap the two sigs in the CBOR string to make it "unordered"
// Original: 82 01 82 [sigA] [sigB]
// [sigA] = 8200581caf00000000000000000000000000000000000000000000000000000000 (32 bytes = 64 chars)
// [sigB] = 8200581cb00000000000000000000000000000000000000000000000000000000 (32 bytes = 64 chars)
const sigA = "8200581caf00000000000000000000000000000000000000000000000000000000";
const sigB = "8200581cb00000000000000000000000000000000000000000000000000000000";
const unorderedCbor = "820182" + sigB + sigA;
const mockUnordered = {
...mockSummonWallet,
rawImportBodies: {
multisig: {
...mockSummonWallet.rawImportBodies.multisig,
payment_script: unorderedCbor
}
}
};
const wallet = buildWallet(mockUnordered, network);
// The address should still be the one from metadata, even if we can't decode the "unordered" CBOR correctly
// This ensures compatibility with legacy scripts that might not follow modern canonical rules.
expect(wallet.capabilities!.address).toBe(mockSummonWallet.rawImportBodies.multisig!.address);
expect(wallet.scriptCbor).toBe(unorderedCbor);
// Even if decoding fails, we should still have a nativeScript object (fallback)
expect(wallet.nativeScript).toBeDefined();
});
});