This repository was archived by the owner on Mar 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathget_contract_data_test.js
113 lines (104 loc) · 2.87 KB
/
get_contract_data_test.js
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
const { xdr } = SorobanClient;
describe('Server#getContractData', function () {
beforeEach(function () {
this.server = new SorobanClient.Server(serverUrl);
this.axiosMock = sinon.mock(AxiosClient);
});
afterEach(function () {
this.axiosMock.verify();
this.axiosMock.restore();
});
let address = 'CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5';
let key = SorobanClient.xdr.ScVal.scvVec([
SorobanClient.xdr.ScVal.scvSymbol('Admin')
]);
it('key found', function (done) {
let result = {
id: address,
sequence: '1'
};
this.axiosMock
.expects('post')
.withArgs(serverUrl, {
jsonrpc: '2.0',
id: 1,
method: 'getLedgerEntries',
params: [
[
xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
key,
contract: new SorobanClient.Contract(address)
.address()
.toScAddress(),
durability: xdr.ContractDataDurability.persistent()
})
).toXDR('base64')
]
]
})
.returns(
Promise.resolve({
data: {
result: {
entries: [result]
}
}
})
);
this.server
.getContractData(address, key, 'persistent')
.then(function (response) {
expect(response).to.be.deep.equal(result);
done();
})
.catch(function (err) {
done(err);
});
});
it('key not found', function (done) {
this.axiosMock
.expects('post')
.withArgs(serverUrl, {
jsonrpc: '2.0',
id: 1,
method: 'getLedgerEntries',
params: [
[
xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
key,
contract: new SorobanClient.Contract(address)
.address()
.toScAddress(),
durability: xdr.ContractDataDurability.temporary()
})
).toXDR('base64')
]
]
})
.returns(Promise.resolve({ data: { result: { entries: [] } } }));
this.server
.getContractData(address, key, 'temporary')
.then(function (_response) {
done(new Error('Expected error'));
})
.catch(function (err) {
done(
err.code == 404
? null
: new Error('Expected error code 404, got: ' + err.code)
);
});
});
it('fails on hex address (was deprecated now unsupported)', function (done) {
let hexAddress = '0'.repeat(63) + '1';
this.server
.getContractData(hexAddress, key, 'persistent')
.then((reply) => done(new Error(`should fail, got: ${reply}`)))
.catch((error) => {
expect(error).to.contain(/unsupported contract id/i);
done();
});
});
});