Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integration tests for LocalTerra as much as possible #3

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions integration-tests/cancelUpgradeProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CancelSoftwareUpgradeProposal } from '../src/core/upgrade/proposals'
const client = new LCDClient({
chainID: 'localterra',
URL: 'http://localhost:1317',
gasPrices: { uusd: 0.38 },
isClassic: !!process.env.TERRA_IS_CLASSIC,
});

// LocalTerra test1 terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v
Expand All @@ -19,21 +19,22 @@ const mk = new MnemonicKey({

const wallet = client.wallet(mk);

const prop = new CancelSoftwareUpgradeProposal("UPGRADE PROPOSAL", "SOFTWARE UPGRADE DESC");
const prop = new CancelSoftwareUpgradeProposal("v6", "SOFTWARE UPGRADE DESC");

async function main() {
const execute = new MsgSubmitProposal(
const msg = new MsgSubmitProposal(
prop,
{ uluna: 10000000 },
wallet.key.accAddress
);

const executeTx = await wallet.createAndSignTx({
msgs: [execute],
const tx = await wallet.createAndSignTx({
msgs: [msg],
});

const executeTxResult = await client.tx.broadcastSync(executeTx);
console.log(executeTxResult);
console.log(JSON.stringify(tx, null, 2));
const result = await client.tx.broadcast(tx);
console.log(result);
}

main().catch(console.error);
13 changes: 6 additions & 7 deletions integration-tests/clikey.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Fee, MsgSend } from '../src';
import { MsgSend } from '../src';
import { LocalTerra } from '../src';
import { CLIKey } from '../src/key/CLIKey';

const terra = new LocalTerra();
const { test1 } = terra.wallets;
const cliKey = new CLIKey({ keyName: 'operator' });
const client = new LocalTerra(!!process.env.TERRA_IS_CLASSIC);
const { test1 } = client.wallets;
const cliKey = new CLIKey({ keyName: 'test0' });

const cliWallet = terra.wallet(cliKey);
const cliWallet = client.wallet(cliKey);

const send = new MsgSend(cliWallet.key.accAddress, test1.key.accAddress, {
uluna: 100000,
Expand All @@ -15,10 +15,9 @@ const send = new MsgSend(cliWallet.key.accAddress, test1.key.accAddress, {
async function main() {
const tx = await cliWallet.createAndSignTx({
msgs: [send],
fee: new Fee(100000, { uluna: 100000 }, '', ''),
});

console.log(await terra.tx.broadcast(tx));
console.log(await client.tx.broadcast(tx));
}

main().catch(console.error);
29 changes: 14 additions & 15 deletions integration-tests/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import {
import { AccessConfig, AccessType } from '../src/core/wasm/AccessConfig';
import * as fs from 'fs';

const isLegacy = false;
const terra = new LocalTerra(isLegacy);
const isClassic = !!process.env.TERRA_IS_CLASSIC;
const client = new LocalTerra(isClassic);

// test1 key from localterra accounts
const { test1 } = terra.wallets;
const { test1 } = client.wallets;

async function main(): Promise<void> {
const storeCode = new MsgStoreCode(
test1.key.accAddress,
fs.readFileSync(isLegacy ? 'contract.wasm.7' : 'contract.wasm.8').toString('base64'),
isLegacy ? undefined : new AccessConfig(AccessType.ACCESS_TYPE_EVERYBODY, "")
fs.readFileSync('contract.wasm.8').toString('base64'),
new AccessConfig(AccessType.ACCESS_TYPE_EVERYBODY, "")
);
const storeCodeTx = await test1.createAndSignTx({
msgs: [storeCode],
});
const storeCodeTxResult = await terra.tx.broadcastBlock(storeCodeTx);
const storeCodeTxResult = await client.tx.broadcastBlock(storeCodeTx);

console.log(storeCodeTxResult);

Expand All @@ -49,7 +49,7 @@ async function main(): Promise<void> {
const instantiateTx = await test1.createAndSignTx({
msgs: [instantiate],
});
const instantiateTxResult = await terra.tx.broadcastBlock(instantiateTx);
const instantiateTxResult = await client.tx.broadcastBlock(instantiateTx);

console.log(instantiateTxResult);

Expand All @@ -59,7 +59,7 @@ async function main(): Promise<void> {
);
}

const contractAddress = getContractAddress(instantiateTxResult, 0, isLegacy);
const contractAddress = getContractAddress(instantiateTxResult, 0);

const execute = new MsgExecuteContract(
test1.key.accAddress, // sender
Expand All @@ -70,16 +70,15 @@ async function main(): Promise<void> {
const executeTx = await test1.createAndSignTx({
msgs: [execute],
});
const executeTxResult = await terra.tx.broadcastBlock(executeTx);
const executeTxResult = await client.tx.broadcastBlock(executeTx);
console.log(executeTxResult);

console.log(await terra.wasm.contractQuery(contractAddress, { "get_count": {} }));
console.log(await client.wasm.contractQuery(contractAddress, { "get_count": {} }));

const [history, _] = await terra.wasm.contractHistory(contractAddress);
const [history, _] = await client.wasm.contractHistory(contractAddress);
console.log(history.map(h => h.toData()));
console.log(JSON.stringify(await terra.wasm.contractInfo(contractAddress)));
console.log(JSON.stringify(await terra.wasm.codeInfo(+codeId)));

console.log(JSON.stringify(await client.wasm.contractInfo(contractAddress)));
console.log(JSON.stringify(await client.wasm.codeInfo(+codeId)));
}

main().then(console.log).catch(console.log)
main().catch(console.log);
21 changes: 6 additions & 15 deletions integration-tests/decodeMsgVerifyInvariant.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import { LCDClient, MsgSend, MnemonicKey } from '../src';
import { SignMode } from '@terraclassic-community/terra.proto/cosmos/tx/signing/v1beta1/signing';
import { TxBody } from '@terraclassic-community/terra.proto/cosmos/tx/v1beta1/tx';
import { LCDClient } from '../src';

async function main() {
const bombay = new LCDClient({
chainID: 'bombay-12',
URL: 'https://bombay-lcd.terra.dev',
gasPrices: { uusd: 0.15 },
const client = new LCDClient({
chainID: 'localterra',
URL: 'http://localhost:1317',
isClassic: !!process.env.TERRA_IS_CLASSIC,
});

(await bombay.tx.txInfosByHeight(8152638)).
(await client.tx.txInfosByHeight(1538)).
map((tx) => {
console.log(JSON.stringify(tx));
});


(await bombay.tx.txInfosByHeight(8153558)).
map((tx) => {
console.log(JSON.stringify(tx));
});

}

main().catch(console.error);
14 changes: 6 additions & 8 deletions integration-tests/decodeTx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LCDClient, MsgSend, MnemonicKey } from '../src';
import { SignMode } from '@terraclassic-community/terra.proto/cosmos/tx/signing/v1beta1/signing';

async function main() {
// create a key out of a mnemonic
Expand All @@ -8,15 +7,14 @@ async function main() {
'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius',
});

const bombay = new LCDClient({
chainID: 'bombay-12',
URL: 'https://bombay-lcd.terra.dev',
gasPrices: { uusd: 0.15 },
const client = new LCDClient({
chainID: 'localterra',
URL: 'http://localhost:1317',
});

// a wallet can be created out of any key
// wallets abstract transaction building
const wallet = bombay.wallet(mk);
const wallet = client.wallet(mk);

// create a simple message that moves coin balances
const send = new MsgSend(
Expand All @@ -32,8 +30,8 @@ async function main() {
});


const encoded = bombay.tx.encode(tx);
const decoded = bombay.tx.decode(encoded);
const encoded = client.tx.encode(tx);
const decoded = client.tx.decode(encoded);

console.log(`\n\tstringified:${JSON.stringify(tx)}`);
console.log(`\n\tencoded:${encoded}`);
Expand Down
30 changes: 11 additions & 19 deletions integration-tests/estimateFee.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
import {
LCDClient,
MsgSend,
Coin,
CreateTxOptions,
} from '../src';
import Axios from 'axios';

async function main() {
const { data: gasPrices } = await Axios.get(
'https://fcd.terra.dev/v1/txs/gas_prices'
);

const columbus = new LCDClient({
chainID: 'columbus-5',
URL: 'https://lcd.terra.dev',
gasPrices,
const client = new LCDClient({
chainID: 'localterra',
URL: 'http://localhost:1317',
isClassic: !!process.env.TERRA_IS_CLASSIC,
});

const accountInfo = await columbus.auth.accountInfo(
'terra1zsky63r58vc7dfn3ljj32ch6fyn4e5qd8skzyz'
const accountInfo = await client.auth.accountInfo(
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
);

const msgs = [
new MsgSend(
'terra1zsky63r58vc7dfn3ljj32ch6fyn4e5qd8skzyz',
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
{ukrw:12345}
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
'terra1zsky63r58vc7dfn3ljj32ch6fyn4e5qd8skzyz',
{ uluna: 1234500 },
),
];

const memo = 'estimate fee';
const txOptions: CreateTxOptions = {
msgs,
memo,
gasPrices,
gasAdjustment: 1.75,
};
// Test raw estimate fee function with specified gas
const rawFee = await columbus.tx.estimateFee(
const rawFee = await client.tx.estimateFee(
[
{
sequenceNumber: accountInfo.getSequenceNumber(),
Expand All @@ -47,7 +39,7 @@ async function main() {
txOptions
);

console.log('MsgSwap(500000 gas): ', rawFee.toData());
console.log('Fee', rawFee.toData());
}

main().catch(console.error);
40 changes: 18 additions & 22 deletions integration-tests/estimateGas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LCDClient, MsgSend, MnemonicKey } from '../src';
import Axios from 'axios';

async function main() {
// create a key out of a mnemonic
Expand All @@ -8,17 +7,13 @@ async function main() {
'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius',
});

const { data: gasPrices } = await Axios.get(
'https://bombay-fcd.terra.dev/v1/txs/gas_prices'
);

const bombay = new LCDClient({
chainID: 'bombay-12',
URL: 'https://bombay-lcd.terra.dev',
gasPrices: { uluna: gasPrices.uluna }
const client = new LCDClient({
chainID: 'localterra',
URL: 'http://localhost:1317',
isClassic: !!process.env.TERRA_IS_CLASSIC,
});

const wallet = bombay.wallet(mk);
const wallet = client.wallet(mk);

// create a simple message that moves coin balances
const send = new MsgSend(
Expand All @@ -28,19 +23,20 @@ async function main() {
);

const tx = await wallet
.createTx({
msgs: [send],
memo: 'test from terra.js!',
.createTx({
msgs: [send],
memo: 'test from terra.js!',
});

const result = await client.tx.estimateGas(tx, {
signers: [
{
sequenceNumber: await wallet.sequence(),
publicKey: wallet.key.publicKey,
},
]
});


const result = await bombay.tx.estimateGas(tx, {signers:[
{
sequenceNumber: await wallet.sequence(),
publicKey: wallet.key.publicKey,
},
]});
console.log(JSON.stringify(result));
console.log('Gas', result);
}

main().catch(console.error);
13 changes: 7 additions & 6 deletions integration-tests/fromContractEvents.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { LCDClient, getContractEvents } from '../src';

const bombay = new LCDClient({
chainID: 'bombay-12',
URL: 'https://bombay-lcd.terra.dev',
const client = new LCDClient({
chainID: 'localterra',
URL: 'http://localhost:1317',
});

bombay.tx
.txInfo('B652DF530D50E470070F3F211519495078082D01B49ED36B762B4E9446CE484E')
client.tx
.txInfo('66F8B52E27B5D6B4CCB7CDF2F10590BF5BFA99D60727E4E17ACB36698CC6AD99')
.then(txInfo => getContractEvents(txInfo))
.then(console.log);
.then(console.log)
.catch(console.error)
15 changes: 7 additions & 8 deletions integration-tests/govQuery.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { LCDClient } from '../src';

async function main() {
const bombay = new LCDClient({
chainID: 'bombay-12',
URL: 'https://bombay-lcd.terra.dev',
gasPrices: { uusd: 0.38 },
const client = new LCDClient({
chainID: 'localterra',
URL: 'http://localhost:1317',
});

console.log(`Proposer: ${JSON.stringify(await bombay.gov.proposer(5320))}`);
console.log(`Proposer: ${JSON.stringify(await client.gov.proposer(1))}`);
console.log(
`Initial Deposit: ${JSON.stringify(await bombay.gov.initialDeposit(5320))}`
`Initial Deposit: ${JSON.stringify(await client.gov.initialDeposit(1))}`
);
console.log(`Deposits: ${JSON.stringify(await bombay.gov.deposits(5320))}`);
console.log(`Votes: ${JSON.stringify(await bombay.gov.votes(5320))}`);
console.log(`Deposits: ${JSON.stringify(await client.gov.deposits(1))}`);
console.log(`Votes: ${JSON.stringify(await client.gov.votes(1))}`);
}

main().catch(console.error);
21 changes: 0 additions & 21 deletions integration-tests/ibc.ts

This file was deleted.

Loading