Skip to content

Commit a0f298f

Browse files
Trinketer22Trinketer22
andauthored
Extra currency optional (#85)
* Make extra currency optional for TonClient * Toncenter as default endpoint for TonClient tests --------- Co-authored-by: Trinketer22 <trinketer22@localhost>
1 parent d5cf147 commit a0f298f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/client/TonClient.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let describeConditional = process.env.TEST_CLIENTS ? describe : describe.skip;
55

66
describeConditional('TonClient', () => {
77
let client = new TonClient({
8-
endpoint: 'https://mainnet.tonhubapi.com/jsonRPC',
8+
endpoint: 'https://toncenter.com/api/v2/jsonRPC',
99
});
1010
const testAddress = Address.parse('EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N');
1111

@@ -43,6 +43,10 @@ describeConditional('TonClient', () => {
4343
console.log(info, shardInfo, wcShards);
4444
});
4545

46+
it('should check contract is deployed', async () => {
47+
expect(await client.isContractDeployed(testAddress)).toBe(true);
48+
});
49+
4650
it('should get extra currency info', async () => {
4751
// EC is rolled out only in testned yet
4852
let testClient = new TonClient({
@@ -52,7 +56,7 @@ describeConditional('TonClient', () => {
5256
let testAddr = Address.parse("0:D36CFC9E0C57F43C1A719CB9F540ED87A694693AE1535B7654B645F52814AFD7");
5357

5458
let res = await testClient.getContractState(testAddr);
55-
let expectedEc =res.extra_currencies.find(e => e.id == 100)!;
59+
let expectedEc = res.extra_currencies?.find(e => e.id == 100)!;
5660
expect(expectedEc).not.toBeUndefined();
5761
expect(BigInt(expectedEc.amount)).toBe(10000000n);
5862
});

src/client/TonClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ function createProvider(client: TonClient, address: Address, init: StateInit | n
441441
throw Error('Unsupported state');
442442
}
443443

444-
if(state.extra_currencies.length > 0) {
444+
if(state.extra_currencies && state.extra_currencies.length > 0) {
445445
ecMap = {};
446446
for(let ec of state.extra_currencies) {
447447
ecMap[ec.id] = BigInt(ec.amount);

src/client/api/HttpApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ const blockIdExt = z.object({
2424

2525
const addressInformation = z.object({
2626
balance: z.union([z.number(), z.string()]),
27-
extra_currencies: z.array(z.object({
27+
extra_currencies: z.optional(z.array(z.object({
2828
'@type': z.literal("extraCurrency"),
2929
id: z.number(),
3030
amount: z.string()
31-
})),
31+
}))),
3232
state: z.union([z.literal('active'), z.literal('uninitialized'), z.literal('frozen')]),
3333
data: z.string(),
3434
code: z.string(),

0 commit comments

Comments
 (0)