Skip to content

Commit 3e8304c

Browse files
committed
Add more failing tests to fix
1 parent a1b653a commit 3e8304c

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

packages/visitors/test/unwrapDefinedTypesVisitor.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,42 @@ test('it follows linked nodes using the correct paths', () => {
7272
definedTypeNode({ name: 'typeA', type: numberTypeNode('u64') }),
7373
);
7474
});
75+
76+
test('it does not unwrap types from the wrong programs', () => {
77+
// Given a program node with a defined type used in another type.
78+
const programA = programNode({
79+
definedTypes: [
80+
definedTypeNode({ name: 'myType', type: numberTypeNode('u8') }),
81+
definedTypeNode({ name: 'myCopyType', type: definedTypeLinkNode('myType') }),
82+
],
83+
name: 'programA',
84+
publicKey: '1111',
85+
});
86+
87+
// And another program with a defined type sharing the same name.
88+
const programB = programNode({
89+
definedTypes: [
90+
definedTypeNode({ name: 'myType', type: numberTypeNode('u16') }),
91+
definedTypeNode({ name: 'myCopyType', type: definedTypeLinkNode('myType') }),
92+
],
93+
name: 'programB',
94+
publicKey: '2222',
95+
});
96+
97+
// When we unwrap the defined type from programA.
98+
const node = rootNode(programA, [programB]);
99+
const result = visit(node, unwrapDefinedTypesVisitor(['myType']));
100+
101+
// Then we expect programA to have been modified but not programB.
102+
assertIsNode(result, 'rootNode');
103+
expect(result).toStrictEqual(
104+
rootNode(
105+
programNode({
106+
definedTypes: [definedTypeNode({ name: 'myCopyType', type: numberTypeNode('u8') })],
107+
name: 'programA',
108+
publicKey: '1111',
109+
}),
110+
[programB],
111+
),
112+
);
113+
});

packages/visitors/test/unwrapInstructionArgsDefinedTypesVisitor.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ test('it unwraps defined type link nodes used as instruction arguments', () => {
3838
],
3939
name: 'MyProgram',
4040
publicKey: '1111',
41-
version: '1.2.3',
4241
}),
4342
);
4443

@@ -70,7 +69,6 @@ test('it unwraps defined type link nodes used as instruction arguments', () => {
7069
],
7170
name: 'MyProgram',
7271
publicKey: '1111',
73-
version: '1.2.3',
7472
}),
7573
),
7674
);
@@ -95,7 +93,6 @@ test('it does not unwrap defined type link nodes that are used in more than one
9593
],
9694
name: 'MyProgram',
9795
publicKey: '1111',
98-
version: '1.2.3',
9996
}),
10097
);
10198

@@ -129,7 +126,6 @@ test('it only unwraps defined type link nodes if they are direct instruction arg
129126
],
130127
name: 'MyProgram',
131128
publicKey: '1111',
132-
version: '1.2.3',
133129
}),
134130
);
135131

@@ -152,7 +148,6 @@ test('it does not unwrap defined type link nodes from other programs', () => {
152148
],
153149
name: 'programA',
154150
publicKey: '1111',
155-
version: '1.2.3',
156151
});
157152

158153
// And another program with a defined type sharing the same name.
@@ -163,7 +158,6 @@ test('it does not unwrap defined type link nodes from other programs', () => {
163158
],
164159
name: 'programB',
165160
publicKey: '2222',
166-
version: '1.2.3',
167161
});
168162

169163
// When we unwrap defined type link nodes for instruction arguments for both of them.
@@ -182,7 +176,6 @@ test('it does not unwrap defined type link nodes from other programs', () => {
182176
],
183177
name: 'programA',
184178
publicKey: '1111',
185-
version: '1.2.3',
186179
}),
187180
[programB],
188181
),

0 commit comments

Comments
 (0)