forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoroban.auth.test.ts
More file actions
69 lines (62 loc) · 1.9 KB
/
Copy pathsoroban.auth.test.ts
File metadata and controls
69 lines (62 loc) · 1.9 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
import { describe, expect, it } from 'vitest';
import { Address, type xdr } from '@stellar/stellar-sdk';
import { SecurityError } from './error-handler';
import { validateSimulationAuth } from './soroban';
describe('validateSimulationAuth', () => {
const contractId = 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4';
it('throws SecurityError when simulation includes an extra unexpected auth entry', () => {
const unexpectedAuthEntry = {} as xdr.SorobanAuthorizationEntry;
const simResult = {
result: {
auth: [unexpectedAuthEntry, unexpectedAuthEntry],
},
};
expect(() =>
validateSimulationAuth(simResult, [
{
contractId,
functionName: 'unlock_assets',
},
]),
).toThrow(SecurityError);
});
it('throws SecurityError when expected root auth includes nested sub-invocations', () => {
const authEntry = {
credentials: () => ({}),
rootInvocation: () => ({
function: () => ({
switch: () => 'contract',
contractFn: () => ({
contractAddress: () => Address.fromString(contractId).toScAddress(),
functionName: () => 'unlock_assets',
}),
}),
subInvocations: () => [
{
function: () => ({
switch: () => 'contract',
contractFn: () => ({
contractAddress: () => Address.fromString(contractId).toScAddress(),
functionName: () => 'malicious_call',
}),
}),
subInvocations: () => [],
},
],
}),
} as xdr.SorobanAuthorizationEntry;
const simResult = {
result: {
auth: [authEntry],
},
};
expect(() =>
validateSimulationAuth(simResult, [
{
contractId,
functionName: 'unlock_assets',
},
]),
).toThrow(SecurityError);
});
});