From ab6ae4d67401ed2947efa6c0a27b4af08cfdc55a Mon Sep 17 00:00:00 2001 From: nhpd Date: Mon, 1 Jul 2024 15:19:51 +0400 Subject: [PATCH 1/2] fix: add test that empty metadata_JSON does not break contract serialization --- src/testcases/run_in_band/slinky.test.ts | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/testcases/run_in_band/slinky.test.ts b/src/testcases/run_in_band/slinky.test.ts index a9bf3ed2..4de70912 100644 --- a/src/testcases/run_in_band/slinky.test.ts +++ b/src/testcases/run_in_band/slinky.test.ts @@ -94,6 +94,26 @@ describe('Neutron / Slinky', () => { }, ], }, + { + ticker: { + currency_pair: { + Base: 'USDT', + Quote: 'USD', + }, + decimals: 6, + min_provider_count: 1, + enabled: false, + metadata_JSON: '', + }, + provider_configs: [ + { + name: 'kraken_api', + off_chain_ticker: 'USDTUSD', + invert: false, + metadata_JSON: '', + }, + ], + }, ], ); }); @@ -220,6 +240,16 @@ describe('Neutron / Slinky', () => { expect(res.market).toBeDefined(); }); + test('query market with empty metadata_JSON', async () => { + const res = await neutronChain.queryContract( + contractAddress, + { + market: { currency_pair: { Base: 'USDT', Quote: 'USD' } }, + }, + ); + expect(res.market).toBeDefined(); + }); + test('query market map', async () => { const res = await neutronChain.queryContract( contractAddress, From d8260ed884a1bb39f2b7bd2315542cdf5503b478 Mon Sep 17 00:00:00 2001 From: nhpd Date: Tue, 2 Jul 2024 19:52:53 +0400 Subject: [PATCH 2/2] also test for last_updated query before marketmap created --- src/testcases/run_in_band/slinky.test.ts | 85 ++++++++++++++---------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/src/testcases/run_in_band/slinky.test.ts b/src/testcases/run_in_band/slinky.test.ts index 4de70912..e85433ee 100644 --- a/src/testcases/run_in_band/slinky.test.ts +++ b/src/testcases/run_in_band/slinky.test.ts @@ -35,6 +35,9 @@ describe('Neutron / Slinky', () => { let proposalId: number; + let oracleContract: string; + let marketmapContract: string; + beforeAll(async () => { testState = new TestStateLocalCosmosTestNet(config); await testState.init(); @@ -66,6 +69,44 @@ describe('Neutron / Slinky', () => { }); }); + describe('prepare: deploy contract', () => { + test('setup oracle contract', async () => { + const codeId = await neutronAccount.storeWasm(NeutronContract.ORACLE); + expect(codeId).toBeGreaterThan(0); + + const res = await neutronAccount.instantiateContract( + codeId, + '{}', + 'oracle', + ); + oracleContract = res[0]._contract_address; + }); + + test('setup marketmap contract', async () => { + const codeId = await neutronAccount.storeWasm(NeutronContract.MARKETMAP); + expect(codeId).toBeGreaterThan(0); + + const res = await neutronAccount.instantiateContract( + codeId, + '{}', + 'marketmap', + ); + marketmapContract = res[0]._contract_address; + }); + }); + + describe('before create market map', () => { + test('query last should return null', async () => { + const res = await neutronChain.queryContract( + marketmapContract, + { + last_updated: {}, + }, + ); + expect(res.last_updated).toBe(null); + }); + }); + describe('submit proposal', () => { test('create proposal', async () => { const chainManagerAddress = (await neutronChain.getChainAdmins())[0]; @@ -157,23 +198,9 @@ describe('Neutron / Slinky', () => { }); describe('wasmbindings oracle', () => { - let contractAddress: string; - - test('setup contract', async () => { - const codeId = await neutronAccount.storeWasm(NeutronContract.ORACLE); - expect(codeId).toBeGreaterThan(0); - - const res = await neutronAccount.instantiateContract( - codeId, - '{}', - 'oracle', - ); - contractAddress = res[0]._contract_address; - }); - test('query prices', async () => { const res = await neutronChain.queryContract( - contractAddress, + oracleContract, { get_prices: { currency_pair_ids: ['TIA/USD'], @@ -186,7 +213,7 @@ describe('Neutron / Slinky', () => { test('query price', async () => { const res = await neutronChain.queryContract( - contractAddress, + oracleContract, { get_price: { currency_pair: { Base: 'TIA', Quote: 'USD' } }, }, @@ -196,7 +223,7 @@ describe('Neutron / Slinky', () => { test('query currencies', async () => { const res = await neutronChain.queryContract( - contractAddress, + oracleContract, { get_all_currency_pairs: {}, }, @@ -206,23 +233,9 @@ describe('Neutron / Slinky', () => { }); }); describe('wasmbindings marketmap', () => { - let contractAddress: string; - - test('setup contract', async () => { - const codeId = await neutronAccount.storeWasm(NeutronContract.MARKETMAP); - expect(codeId).toBeGreaterThan(0); - - const res = await neutronAccount.instantiateContract( - codeId, - '{}', - 'marketmap', - ); - contractAddress = res[0]._contract_address; - }); - test('query last', async () => { const res = await neutronChain.queryContract( - contractAddress, + marketmapContract, { last_updated: {}, }, @@ -232,7 +245,7 @@ describe('Neutron / Slinky', () => { test('query market', async () => { const res = await neutronChain.queryContract( - contractAddress, + marketmapContract, { market: { currency_pair: { Base: 'TIA', Quote: 'USD' } }, }, @@ -242,7 +255,7 @@ describe('Neutron / Slinky', () => { test('query market with empty metadata_JSON', async () => { const res = await neutronChain.queryContract( - contractAddress, + marketmapContract, { market: { currency_pair: { Base: 'USDT', Quote: 'USD' } }, }, @@ -252,7 +265,7 @@ describe('Neutron / Slinky', () => { test('query market map', async () => { const res = await neutronChain.queryContract( - contractAddress, + marketmapContract, { market_map: {}, }, @@ -265,7 +278,7 @@ describe('Neutron / Slinky', () => { test('query params', async () => { const res = await neutronChain.queryContract( - contractAddress, + marketmapContract, { params: {}, },