-
Notifications
You must be signed in to change notification settings - Fork 579
Expand file tree
/
Copy pathAssociatedTokenDetailsCard.spec.tsx
More file actions
142 lines (128 loc) · 5.96 KB
/
AssociatedTokenDetailsCard.spec.tsx
File metadata and controls
142 lines (128 loc) · 5.96 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { intoTransactionInstructionFromVersionedMessage } from '@components/inspector/utils';
import * as spl from '@solana/spl-token';
import { render, screen } from '@testing-library/react';
import * as stubs from '@/app/__tests__/mock-stubs';
import * as mock from '@/app/__tests__/mocks';
import { AccountsProvider } from '@/app/providers/accounts';
import { ClusterProvider } from '@/app/providers/cluster';
import { ScrollAnchorProvider } from '@/app/providers/scroll-anchor';
import { intoParsedInstruction } from '../../inspector/into-parsed-data';
import { AssociatedTokenDetailsCard } from '../associated-token/AssociatedTokenDetailsCard';
describe('inspector::AssociatedTokenDetailsCard', () => {
test('should render "CreateIdempotent" card', async () => {
const index = 1;
const m = mock.deserializeMessageV0(stubs.aTokenCreateIdempotentMsg);
const mci = m.compiledInstructions[index];
const ti = intoTransactionInstructionFromVersionedMessage(mci, m);
expect(ti.programId.equals(spl.ASSOCIATED_TOKEN_PROGRAM_ID)).toBeTruthy();
const ix = intoParsedInstruction(ti);
// check that component is rendered properly
render(
<ScrollAnchorProvider>
<ClusterProvider>
<AccountsProvider>
<AssociatedTokenDetailsCard
ix={ix}
raw={mci}
message={m}
index={index}
result={{ err: null }}
/>
</AccountsProvider>
</ClusterProvider>
</ScrollAnchorProvider>
);
expect(screen.getByText(/Associated Token Program: Create Idempotent/)).toBeInTheDocument();
[/Source/, /Account/, /Mint/, /Wallet/].forEach(pattern => {
expect(screen.getByText(pattern)).toBeInTheDocument();
});
expect(screen.queryAllByText(/^System Program$/)).toHaveLength(3);
expect(screen.queryAllByText(/^Token Program$/)).toHaveLength(1);
});
test('should render "Create" card', async () => {
const index = 2;
const m = mock.deserializeMessage(stubs.aTokenCreateMsgWithInnerCards);
const mci = m.compiledInstructions[index];
const ti = intoTransactionInstructionFromVersionedMessage(mci, m);
expect(ti.programId.equals(spl.ASSOCIATED_TOKEN_PROGRAM_ID)).toBeTruthy();
const ix = intoParsedInstruction(ti);
// check that component is rendered properly
render(
<ScrollAnchorProvider>
<ClusterProvider>
<AccountsProvider>
<AssociatedTokenDetailsCard
ix={ix}
raw={mci}
message={m}
index={index}
result={{ err: null }}
/>
</AccountsProvider>
</ClusterProvider>
</ScrollAnchorProvider>
);
expect(screen.getByText(/Associated Token Program: Create$/)).toBeInTheDocument();
[/Source/, /Account/, /Mint/, /Wallet/].forEach(pattern => {
expect(screen.getByText(pattern)).toBeInTheDocument();
});
expect(screen.queryAllByText(/^System Program$/)).toHaveLength(3);
expect(screen.queryAllByText(/^Token Program$/)).toHaveLength(3);
});
test('should render "RecoverNested" card', async () => {
const index = 0;
const m = mock.deserializeMessage(stubs.aTokenRecoverNestedMsg);
const mci = m.compiledInstructions[index];
const ti = intoTransactionInstructionFromVersionedMessage(mci, m);
expect(ti.programId.equals(spl.ASSOCIATED_TOKEN_PROGRAM_ID)).toBeTruthy();
const ix = intoParsedInstruction(ti);
// check that component is rendered properly
render(
<ScrollAnchorProvider>
<ClusterProvider>
<AccountsProvider>
<AssociatedTokenDetailsCard
ix={ix}
raw={mci}
message={m}
index={index}
result={{ err: null }}
/>
</AccountsProvider>
</ClusterProvider>
</ScrollAnchorProvider>
);
expect(screen.getByText(/Associated Token Program: Recover Nested/)).toBeInTheDocument();
[/Destination/, /Nested Mint/, /Nested Owner/, /Nested Source/, /Owner Mint/, /^Owner$/].forEach(pattern => {
expect(screen.getByText(pattern)).toBeInTheDocument();
});
expect(screen.queryAllByText(/^Token Program$/)).toHaveLength(3);
});
});
describe('inspector::AssociatedTokenDetailsCard with inner cards', () => {
test('should render "CreateIdempotentDetailsCard"', async () => {
const index = 1;
const m = mock.deserializeMessageV0(stubs.aTokenCreateIdempotentMsgWithInnerCards);
const mci = m.compiledInstructions[index];
const ti = intoTransactionInstructionFromVersionedMessage(mci, m);
expect(ti.programId.equals(spl.ASSOCIATED_TOKEN_PROGRAM_ID)).toBeTruthy();
const ix = intoParsedInstruction(ti);
// check that component is rendered properly
render(
<ScrollAnchorProvider>
<ClusterProvider>
<AccountsProvider>
<AssociatedTokenDetailsCard
ix={ix}
raw={mci}
message={m}
index={index}
result={{ err: null }}
/>
</AccountsProvider>
</ClusterProvider>
</ScrollAnchorProvider>
);
expect(screen.queryByText(/Inner Instructions/)).not.toBeInTheDocument();
});
});