diff --git a/integration-tests/cancelUpgradeProposal.ts b/integration-tests/cancelUpgradeProposal.ts index 961be57..e4c6b30 100644 --- a/integration-tests/cancelUpgradeProposal.ts +++ b/integration-tests/cancelUpgradeProposal.ts @@ -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 @@ -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); diff --git a/integration-tests/clikey.ts b/integration-tests/clikey.ts index 39c6118..6703ff6 100644 --- a/integration-tests/clikey.ts +++ b/integration-tests/clikey.ts @@ -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, @@ -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); diff --git a/integration-tests/contract.ts b/integration-tests/contract.ts index c5a6235..337104a 100644 --- a/integration-tests/contract.ts +++ b/integration-tests/contract.ts @@ -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 { 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); @@ -49,7 +49,7 @@ async function main(): Promise { const instantiateTx = await test1.createAndSignTx({ msgs: [instantiate], }); - const instantiateTxResult = await terra.tx.broadcastBlock(instantiateTx); + const instantiateTxResult = await client.tx.broadcastBlock(instantiateTx); console.log(instantiateTxResult); @@ -59,7 +59,7 @@ async function main(): Promise { ); } - const contractAddress = getContractAddress(instantiateTxResult, 0, isLegacy); + const contractAddress = getContractAddress(instantiateTxResult, 0); const execute = new MsgExecuteContract( test1.key.accAddress, // sender @@ -70,16 +70,15 @@ async function main(): Promise { 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); diff --git a/integration-tests/decodeMsgVerifyInvariant.ts b/integration-tests/decodeMsgVerifyInvariant.ts index 724a0f3..5800860 100644 --- a/integration-tests/decodeMsgVerifyInvariant.ts +++ b/integration-tests/decodeMsgVerifyInvariant.ts @@ -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); diff --git a/integration-tests/decodeTx.ts b/integration-tests/decodeTx.ts index 3d97806..06a5725 100644 --- a/integration-tests/decodeTx.ts +++ b/integration-tests/decodeTx.ts @@ -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 @@ -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( @@ -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}`); diff --git a/integration-tests/estimateFee.ts b/integration-tests/estimateFee.ts index 3755d78..1c91d8a 100644 --- a/integration-tests/estimateFee.ts +++ b/integration-tests/estimateFee.ts @@ -1,31 +1,25 @@ 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 }, ), ]; @@ -33,11 +27,9 @@ async function main() { 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(), @@ -47,7 +39,7 @@ async function main() { txOptions ); - console.log('MsgSwap(500000 gas): ', rawFee.toData()); + console.log('Fee', rawFee.toData()); } main().catch(console.error); diff --git a/integration-tests/estimateGas.ts b/integration-tests/estimateGas.ts index a442beb..a9b1adf 100644 --- a/integration-tests/estimateGas.ts +++ b/integration-tests/estimateGas.ts @@ -1,5 +1,4 @@ import { LCDClient, MsgSend, MnemonicKey } from '../src'; -import Axios from 'axios'; async function main() { // create a key out of a mnemonic @@ -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( @@ -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); diff --git a/integration-tests/fromContractEvents.ts b/integration-tests/fromContractEvents.ts index 9a275e3..79147ef 100644 --- a/integration-tests/fromContractEvents.ts +++ b/integration-tests/fromContractEvents.ts @@ -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) diff --git a/integration-tests/govQuery.ts b/integration-tests/govQuery.ts index 106bb83..5370499 100644 --- a/integration-tests/govQuery.ts +++ b/integration-tests/govQuery.ts @@ -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); diff --git a/integration-tests/ibc.ts b/integration-tests/ibc.ts deleted file mode 100644 index 149e28a..0000000 --- a/integration-tests/ibc.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { LCDClient } from '../src'; - -async function main() { - const bombay = new LCDClient({ - chainID: 'localterra', - URL: 'http://localhost:1317', - gasPrices: { uusd: 0.38 }, - }); - - console.log( - `Txs Page 1: ${JSON.stringify( - ( - await bombay.tx.search({ - events: [{ key: 'tx.height', value: '12' }], - 'pagination.limit': '50', - }) - ).txs.map(tx => tx) - )}` - ); -} -main().catch(console.error); diff --git a/integration-tests/msgauth.ts b/integration-tests/msgauth.ts index ccfdc19..94baaf5 100644 --- a/integration-tests/msgauth.ts +++ b/integration-tests/msgauth.ts @@ -8,6 +8,7 @@ import { Coins, MsgExecAuthorized, MsgRevokeAuthorization, + AuthorizationGrant, } from '../src'; function grant( @@ -20,8 +21,7 @@ function grant( new MsgGrantAuthorization( granter.key.accAddress, grantee.key.accAddress, - new SendAuthorization(spendLimit), - expiration + new AuthorizationGrant(new SendAuthorization(spendLimit), expiration), ), ]; @@ -63,7 +63,7 @@ async function main() { const client = new LCDClient({ URL: 'http://localhost:1317', chainID: 'localterra', - gasPrices: '169.77ukrw', + isClassic: !!process.env.TERRA_IS_CLASSIC, }); // Granter (terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v) @@ -87,7 +87,7 @@ async function main() { granter, grantee, // Set enough spend limit since it will be decreased upon every MsgSend transactions - '1000000000000000ukrw', + '1000000000000000uluna', // expire after 100 year new Date('2050-01-01') ) @@ -107,7 +107,7 @@ async function main() { grantee, // Test3 'terra1757tkx08n0cqrw7p86ny9lnxsqeth0wgp0em95', - '2000000000000ukrw' + '1000000uluna' ) .then(tx => client.tx.broadcast(tx)) .then(console.info) diff --git a/integration-tests/paramchangeproposal.ts b/integration-tests/paramchangeproposal.ts index 2c12fd1..fedd43b 100644 --- a/integration-tests/paramchangeproposal.ts +++ b/integration-tests/paramchangeproposal.ts @@ -5,8 +5,8 @@ import { } from '../src'; // test1 key from localterra accounts -const terra = new LocalTerra(); -const { test1 } = terra.wallets; +const client = new LocalTerra(!!process.env.TERRA_IS_CLASSIC); +const { test1 } = client.wallets; const proposal = new ParameterChangeProposal('testing params', 'yay!', [ { @@ -171,24 +171,9 @@ const proposal = new ParameterChangeProposal('testing params', 'yay!', [ key: 'BlocksPerYear', value: '"6311520"', }, - { - subspace: 'wasm', - key: 'MaxContractSize', - value: '"614400"', - }, - { - subspace: 'wasm', - key: 'MaxContractGas', - value: '"20000000"', - }, - { - subspace: 'wasm', - key: 'MaxContractMsgSize', - value: '"4096"', - }, ]); -async function main(): Promise { +async function main() { const submitProposal = new MsgSubmitProposal( proposal, {}, @@ -199,8 +184,9 @@ async function main(): Promise { msgs: [submitProposal], }); - const result = await terra.tx.broadcast(tx); + console.log(JSON.stringify(tx, null, 2)); + const result = await client.tx.broadcast(tx); console.log(result); } -main().then(console.log); +main().catch(console.error); diff --git a/integration-tests/parseIbcMsgUpdateClient.ts b/integration-tests/parseIbcMsgUpdateClient.ts index 61baf85..8fbefca 100644 --- a/integration-tests/parseIbcMsgUpdateClient.ts +++ b/integration-tests/parseIbcMsgUpdateClient.ts @@ -1,13 +1,12 @@ -import { Any } from '@terraclassic-community/terra.proto/google/protobuf/any'; import { assert } from 'console'; -import { LCDClient, Msg, MsgUpdateClient } from '../src'; +import { LCDClient, MsgUpdateClient } from '../src'; async function main() { - const terra = new LCDClient({ + const client = new LCDClient({ chainID: 'columbus-5', - URL: 'https://lcd.terra.dev', + URL: 'https://columbus-lcd.terra.dev', }); - const originalTx = await terra.tx.txInfo('6aff2666ab32c95b670709f4b1ca57e63f2e72ca656f2d3c4b4fc43f3a54760f'); + const originalTx = await client.tx.txInfo('6aff2666ab32c95b670709f4b1ca57e63f2e72ca656f2d3c4b4fc43f3a54760f'); const data = MsgUpdateClient.fromData(originalTx.tx.body.messages[0].toData() as MsgUpdateClient.Data).toJSON(); const proto = MsgUpdateClient.fromProto(originalTx.tx.body.messages[0].toProto() as MsgUpdateClient.Proto).toJSON(); assert(data === proto, "conversion error") diff --git a/integration-tests/send.ts b/integration-tests/send.ts index a3098fb..4ef975f 100644 --- a/integration-tests/send.ts +++ b/integration-tests/send.ts @@ -1,5 +1,4 @@ -import { LCDClient, MsgSend, MnemonicKey } from '../src'; -import { SignMode } from '@terraclassic-community/terra.proto/cosmos/tx/signing/v1beta1/signing'; +import { LCDClient, MsgSend, MnemonicKey, Fee } from '../src'; async function main() { // create a key out of a mnemonic @@ -8,40 +7,34 @@ 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({ + const client = new LCDClient({ chainID: 'localterra', URL: 'http://localhost:1317', + isClassic: !!process.env.TERRA_IS_CLASSIC, }); // 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( 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', 'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', - { uluna: 1000 } + { uluna: 1000000 } ); - wallet + await wallet .createAndSignTx({ - signMode: SignMode.SIGN_MODE_LEGACY_AMINO_JSON, msgs: [send], memo: 'test from terra.js!', }) .then(tx => { - /* - tx.body.messages[0] = new MsgSend( - 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', - 'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', - { uluna: 2000 } - ); - */ - return bombay.tx.broadcast(tx); + console.log(JSON.stringify(tx, null, 2)); + return client.tx.broadcast(tx); }) .then(result => { - console.log(`TX hash: ${result.txhash} ${result.raw_log}`); + console.log(result); }); } diff --git a/integration-tests/sendLegacyAmino.ts b/integration-tests/sendLegacyAmino.ts index b6b1c98..2900a01 100644 --- a/integration-tests/sendLegacyAmino.ts +++ b/integration-tests/sendLegacyAmino.ts @@ -1,5 +1,5 @@ -import { LCDClient, MsgSend, MnemonicKey } from '../src'; -import { SignMode } from '@terraclassic-community/terra.proto/cosmos/tx/signing/v1beta1/signing'; +import { LCDClient, MsgSend, MnemonicKey, Fee } from '../src'; +import { SignMode } from '@classic-terra/terra.proto/cosmos/tx/signing/v1beta1/signing'; async function main() { // create a key out of a mnemonic @@ -8,34 +8,36 @@ 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.38 }, + const client = new LCDClient({ + chainID: 'localterra', + URL: 'http://localhost:1317', + isClassic: !!process.env.TERRA_IS_CLASSIC, }); // 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( 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', 'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', - { uusd: 1312029 } + { uluna: 1000000 } ); - wallet + await wallet .createAndSignTx({ msgs: [send], memo: 'test from terra.js!', - gas: '109504', signMode: SignMode.SIGN_MODE_LEGACY_AMINO_JSON, }) - .then(tx => bombay.tx.broadcast(tx)) + .then(tx => { + console.log(JSON.stringify(tx, null, 2)); + return client.tx.broadcast(tx); + }) .then(result => { - console.log(`TX hash: ${result.txhash}`); - }); + console.log(result); + }) } main().catch(console.error); diff --git a/integration-tests/sendMultisend.ts b/integration-tests/sendMultisend.ts index 40c61f0..f272e48 100644 --- a/integration-tests/sendMultisend.ts +++ b/integration-tests/sendMultisend.ts @@ -1,4 +1,4 @@ -import { LCDClient, MnemonicKey, MsgMultiSend, SignDoc } from '../src'; +import { LCDClient, MnemonicKey, MsgMultiSend, SignDoc, Fee } from '../src'; async function main() { // create a key out of a mnemonic @@ -9,14 +9,13 @@ async function main() { const mk2 = new MnemonicKey({ mnemonic: - 'quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty' + 'quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty' }); - const bombay = new LCDClient({ + const client = new LCDClient({ chainID: 'localterra', URL: 'http://localhost:1317', - gasPrices: { uluna: 0.38 }, - isClassic: true + isClassic: !!process.env.TERRA_IS_CLASSIC, }); // create a simple message that moves coin balances @@ -39,48 +38,53 @@ async function main() { ] ); - const accInfo = await bombay.auth.accountInfo(mk.accAddress); - const accInfo2 = await bombay.auth.accountInfo(mk2.accAddress); + const accInfo = await client.auth.accountInfo(mk.accAddress); + const accInfo2 = await client.auth.accountInfo(mk2.accAddress); - const tx = await bombay.tx.create( + const tx = await client.tx.create( [ - { address: mk.accAddress, sequenceNumber: accInfo.getSequenceNumber() }, - { address: mk2.accAddress, sequenceNumber: accInfo2.getSequenceNumber() }, + { + address: mk.accAddress, + sequenceNumber: accInfo.getSequenceNumber(), + publicKey: accInfo.getPublicKey(), + }, + { address: mk2.accAddress, + sequenceNumber: accInfo2.getSequenceNumber(), + publicKey: accInfo2.getPublicKey(), + }, ], { msgs: [send], memo: 'memo', - gasPrices: { uluna: 0.456 }, - gasAdjustment: 1.4, } ); const sig1 = await mk.createSignatureAmino( new SignDoc( - bombay.config.chainID, + client.config.chainID, accInfo.getAccountNumber(), accInfo.getSequenceNumber(), tx.auth_info, tx.body ), - bombay.config.isClassic + client.config.isClassic, ); - console.log(`accinfo1:${accInfo}`); const sig2 = await mk2.createSignatureAmino( new SignDoc( - bombay.config.chainID, + client.config.chainID, accInfo2.getAccountNumber(), accInfo2.getSequenceNumber(), tx.auth_info, tx.body ), - bombay.config.isClassic + client.config.isClassic, ); tx.appendSignatures([sig1, sig2]); - console.log(JSON.stringify(tx.toData())); - bombay.tx.broadcast(tx).then(console.log); + console.log(JSON.stringify(tx, null, 2)); + const result = await client.tx.broadcast(tx); + console.log(result); } main().catch(console.error); diff --git a/integration-tests/sendMultisig.ts b/integration-tests/sendMultisig.ts index c05d0d7..9763d94 100644 --- a/integration-tests/sendMultisig.ts +++ b/integration-tests/sendMultisig.ts @@ -35,10 +35,10 @@ async function main() { mk3.publicKey as SimplePublicKey, ]); - const bombay = new LCDClient({ + const client = new LCDClient({ chainID: 'localterra', URL: 'http://localhost:1317', - gasPrices: { uusd: 0.38 }, + isClassic: !!process.env.TERRA_IS_CLASSIC, }); const address = multisigPubkey.address(); @@ -48,11 +48,11 @@ async function main() { const send = new MsgSend( address, 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', - { uusd: 100000 } + { uluna: 10000 } ); - const accInfo = await bombay.auth.accountInfo(address); - const tx = await bombay.tx.create( + const accInfo = await client.auth.accountInfo(address); + const tx = await client.tx.create( [ { address, @@ -63,29 +63,29 @@ async function main() { { msgs: [send], memo: 'memo', - gasPrices: { uusd: 0.456 }, - gasAdjustment: 1.2, } ); const sig1 = await mk3.createSignatureAmino( new SignDoc( - bombay.config.chainID, + client.config.chainID, accInfo.getAccountNumber(), accInfo.getSequenceNumber(), tx.auth_info, tx.body - ) + ), + client.config.isClassic, ); const sig2 = await mk2.createSignatureAmino( new SignDoc( - bombay.config.chainID, + client.config.chainID, accInfo.getAccountNumber(), accInfo.getSequenceNumber(), tx.auth_info, tx.body - ) + ), + client.config.isClassic, ); multisig.appendSignatureV2s([sig1, sig2]); @@ -96,8 +96,9 @@ async function main() { accInfo.getSequenceNumber() ), ]); - console.log(JSON.stringify(tx.toData())); - bombay.tx.broadcastBlock(tx).then(console.log); + console.log(JSON.stringify(tx.toData(), null, 2)); + const result = await client.tx.broadcastBlock(tx); + console.log(result); } main().catch(console.error); diff --git a/integration-tests/submitProposal.ts b/integration-tests/submitProposal.ts index 95abbac..877c3c8 100644 --- a/integration-tests/submitProposal.ts +++ b/integration-tests/submitProposal.ts @@ -8,8 +8,9 @@ import { } from '../src'; const client = new LCDClient({ - chainID: 'bombay-12', - URL: 'https://bombay-lcd.terra.dev', + chainID: 'localterra', + URL: 'http://localhost:1317', + isClassic: !!process.env.TERRA_IS_CLASSIC, }); // LocalTerra test1 terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v @@ -31,16 +32,17 @@ async function main() { description, changes ), - { uluna: 10000000 }, + { uluna: 1000000 }, wallet.key.accAddress ); - const executeTx = await wallet.createAndSignTx({ + const tx = await wallet.createAndSignTx({ msgs: [execute], }); - 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); diff --git a/integration-tests/submitUpgradeProposal.ts b/integration-tests/submitUpgradeProposal.ts index 7924f7c..94321c3 100644 --- a/integration-tests/submitUpgradeProposal.ts +++ b/integration-tests/submitUpgradeProposal.ts @@ -5,7 +5,7 @@ import { SoftwareUpgradeProposal } 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 @@ -20,7 +20,7 @@ async function main() { const blockInfo = await client.tendermint.blockInfo(); const plan = new Plan( - 'v0.5.3', + 'v6', undefined, (+blockInfo.block.header.height + 100).toString(), 'planinfo', @@ -32,18 +32,19 @@ async function main() { plan ); - 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.broadcastSync(tx); + console.log(result); } main().catch(console.error); diff --git a/integration-tests/swap.ts b/integration-tests/swap.ts new file mode 100644 index 0000000..1d5a4bc --- /dev/null +++ b/integration-tests/swap.ts @@ -0,0 +1,36 @@ +import { LCDClient, MsgSwap, Coin, MnemonicKey } from '../src'; + +async function main() { + const mk = new MnemonicKey({ + mnemonic: + '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 client = new LCDClient({ + chainID: 'localterra', + URL: 'http://localhost:1317', + isClassic: !!process.env.TERRA_IS_CLASSIC, + }); + + const wallet = client.wallet(mk); + const msg = new MsgSwap( + 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + new Coin('uluna', 1_000_000_000), + 'uusd' + ); + + await wallet + .createAndSignTx({ + msgs: [msg], + memo: 'swap from terra.js!', + }) + .then(tx => { + console.log(JSON.stringify(tx, null, 2)); + return client.tx.broadcast(tx); + }) + .then(result => { + console.log(result); + }); +} + +main().catch(console.error); diff --git a/integration-tests/txSearch.ts b/integration-tests/txSearch.ts index 3556c01..bad0b44 100644 --- a/integration-tests/txSearch.ts +++ b/integration-tests/txSearch.ts @@ -1,18 +1,19 @@ import { LCDClient } from '../src'; async function main() { - const terra = new LCDClient({ + const client = new LCDClient({ chainID: 'localterra', URL: 'http://localhost:1317', - gasPrices: { uusd: 0.38 }, }); console.log( `Txs Page 1: ${JSON.stringify( ( - await terra.tx.search({ - events: [{ key: 'tx.height', value: '8343' }, - {key:'message.sender', value:'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38p'}], + await client.tx.search({ + events: [ + { key: 'tx.height', value: '8343' }, + { key: 'message.sender', value: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38p' }, + ], 'pagination.limit': '100', }) ).txs.map(tx => tx.txhash) @@ -22,7 +23,7 @@ async function main() { console.log( `Txs Page 2: ${JSON.stringify( ( - await terra.tx.search({ + await client.tx.search({ events: [{ key: 'tx.height', value: '8345' }], 'pagination.limit': '50', 'pagination.offset': '1', diff --git a/integration-tests/validatorsWithVotingPower.ts b/integration-tests/validatorsWithVotingPower.ts index 8c7cc8e..e92c7a2 100644 --- a/integration-tests/validatorsWithVotingPower.ts +++ b/integration-tests/validatorsWithVotingPower.ts @@ -1,8 +1,8 @@ import { LCDClient } from '../src'; -const terra = new LCDClient({ - chainID: 'bombay-12', - URL: 'https://bombay-lcd.terra.dev', +const client = new LCDClient({ + chainID: 'localterra', + URL: 'http://localhost:1317', }); -terra.utils.validatorsWithVotingPower().then(x => console.log(x)); +client.utils.validatorsWithVotingPower().then(x => console.log(x)); diff --git a/integration-tests/websocket.ts b/integration-tests/websocket.ts index 8a7029c..a0f1cb0 100644 --- a/integration-tests/websocket.ts +++ b/integration-tests/websocket.ts @@ -1,19 +1,29 @@ -import { LocalTerra, WebSocketClient } from '../src'; +import { WebSocketClient } from '../src'; const wsclient = new WebSocketClient('ws://localhost:26657/websocket'); -const terra = new LocalTerra(); -let count = 0; -wsclient.subscribe('NewBlock', {}, () => { - console.log(count); - count += 1; +// New block event +// let count = 0; - if (count === 3) { - wsclient.destroy(); - } -}); +// wsclient.subscribe('NewBlock', {}, () => { +// console.log(count); +// count += 1; + +// if (count === 3) { +// wsclient.destroy(); +// } +// }); + +// MsgSwap +// wsclient.subscribeTx({ 'message.action': '/terra.market.v1beta1.MsgSwap' }, async data => { +// console.log('Swap occured!'); +// const txInfo = await client.tx.txInfo(data.value.TxResult.txhash); +// if (txInfo.logs) { +// console.log(txInfo.logs[0].eventsByType); +// } +// }); -// send tracker +// MsgSend wsclient.subscribe( 'Tx', { @@ -26,13 +36,4 @@ wsclient.subscribe( } ); -// swap tracker -wsclient.subscribeTx({ 'message.action': '/terra.market.v1beta1.MsgSwap' }, async data => { - console.log('Swap occured!'); - const txInfo = await terra.tx.txInfo(data.value.TxResult.txhash); - if (txInfo.logs) { - console.log(txInfo.logs[0].eventsByType); - } -}); - wsclient.start(); diff --git a/src/client/lcd/LCDClient.ts b/src/client/lcd/LCDClient.ts index 7edff21..89e20c8 100644 --- a/src/client/lcd/LCDClient.ts +++ b/src/client/lcd/LCDClient.ts @@ -52,16 +52,15 @@ export interface LCDClientConfig { } const DEFAULT_LCD_OPTIONS: Partial = { - gasAdjustment: 1.75, + gasAdjustment: 2.0, }; // isClassic network: true // forked network : false -const DEFAULT_NETWORK_TYPE_BY_CHAIN_ID: { [key: string]: boolean } = { +const IS_CLASSIC_BY_CHAIN_ID: { [key: string]: boolean } = { default: false, 'columbus-5': true, - 'bombay-12': true, - 'pisco-1': false, + 'rebel-2': true, }; const DEFAULT_GAS_PRICES_BY_CHAIN_ID: { [key: string]: Coins.Input } = { @@ -69,13 +68,10 @@ const DEFAULT_GAS_PRICES_BY_CHAIN_ID: { [key: string]: Coins.Input } = { uluna: 0.15, }, 'columbus-5': { - uusd: 0.15, + uluna: 30.0, }, - 'bombay-12': { - uusd: 0.15, - }, - 'pisco-1': { - uluna: 0.15, + 'rebel-2': { + uluna: 30.0, }, }; @@ -133,8 +129,8 @@ export class LCDClient { DEFAULT_GAS_PRICES_BY_CHAIN_ID[config.chainID] || DEFAULT_GAS_PRICES_BY_CHAIN_ID['default'], isClassic: - DEFAULT_NETWORK_TYPE_BY_CHAIN_ID[config.chainID] || - DEFAULT_NETWORK_TYPE_BY_CHAIN_ID['default'], + IS_CLASSIC_BY_CHAIN_ID[config.chainID] || + IS_CLASSIC_BY_CHAIN_ID['default'], ...config, }; diff --git a/src/client/lcd/api/TxAPI.ts b/src/client/lcd/api/TxAPI.ts index cc5d8bc..66d4059 100644 --- a/src/client/lcd/api/TxAPI.ts +++ b/src/client/lcd/api/TxAPI.ts @@ -292,9 +292,7 @@ export class TxAPI extends BaseAPI { const gasPrices = options.gasPrices || this.lcd.config.gasPrices; const gasAdjustment = options.gasAdjustment || this.lcd.config.gasAdjustment; - const feeDenoms = options.feeDenoms || [ - this.lcd.config.isClassic ? 'uusd' : 'uluna', - ]; + const feeDenoms = options.feeDenoms || ['uluna']; let gas = options.gas; let gasPricesCoins: Coins | undefined; @@ -321,14 +319,16 @@ export class TxAPI extends BaseAPI { // simulate gas if (!gas || gas === 'auto' || gas === '0') { - gas = (await this.estimateGas(tx, { gasAdjustment })).toString(); + gas = await this.estimateGas(tx, { gasAdjustment }); } - const feeAmount = gasPricesCoins + let feeAmount = gasPricesCoins ? gasPricesCoins.mul(gas).toIntCeilCoins() - : this.lcd.config.isClassic - ? '0uusd' - : '0uluna'; + : new Coins('0uluna'); + + if (this.lcd.config.isClassic) { + feeAmount = feeAmount.add(await this.computeTax(tx)); + } return new Fee(Number.parseInt(gas), feeAmount, '', ''); } @@ -339,7 +339,7 @@ export class TxAPI extends BaseAPI { gasAdjustment?: Numeric.Input; signers?: SignerData[]; } - ): Promise { + ): Promise { const gasAdjustment = options?.gasAdjustment || this.lcd.config.gasAdjustment; @@ -360,11 +360,22 @@ export class TxAPI extends BaseAPI { }) .then(d => SimulateResponse.fromData(d)); - return new Dec(gasAdjustment).mul(simulateRes.gas_info.gas_used).toNumber(); + return new Dec(gasAdjustment) + .mul(simulateRes.gas_info.gas_used) + .truncated() + .toString(); } - public async computeTax(): Promise { - throw new Error('Tax was removed from network'); + public async computeTax(tx: Tx): Promise { + if (!this.lcd.config.isClassic) { + throw new Error('Tax was removed from network'); + } + + return await this.c + .post<{ tax_amount: Coins.Data }>(`/terra/tx/v1beta1/compute_tax`, { + tx_bytes: this.encode(tx), + }) + .then(d => Coins.fromData(d.tax_amount)); } /** diff --git a/src/util/contract.ts b/src/util/contract.ts index 5f79fab..5b7d50b 100644 --- a/src/util/contract.ts +++ b/src/util/contract.ts @@ -23,8 +23,7 @@ export function getCodeId( export function getContractAddress( txResult: WaitTxBroadcastResult | BlockTxBroadcastResult | TxInfo, - msgIndex = 0, - isClassic = false + msgIndex = 0 ): string { if ( isTxError(txResult) || @@ -33,17 +32,13 @@ export function getContractAddress( ) { throw new Error('could not parse contract address -- tx logs are empty.'); } - let eventName: string; - let attributeKey: string; - if (isClassic) { - eventName = 'instantiate_contract'; - attributeKey = 'contract_address'; - } else { - eventName = 'wasm'; - attributeKey = '_contract_address'; - } + + const eventName = 'wasm'; + const attributeKey = '_contract_address'; + const contractAddress = txResult.logs[msgIndex].eventsByType[eventName][attributeKey][0]; + return contractAddress; } @@ -54,8 +49,7 @@ export interface ContractEvent { export function getContractEvents( txResult: WaitTxBroadcastResult | BlockTxBroadcastResult | TxInfo, - msgIndex = 0, - isClassic = false + msgIndex = 0 ): ContractEvent[] { if ( isTxError(txResult) || @@ -65,15 +59,8 @@ export function getContractEvents( throw new Error('could not parse contract events -- tx logs are empty.'); } - let eventName: string; - let attributeKey: string; - if (isClassic) { - eventName = 'from_contract'; - attributeKey = 'contract_address'; - } else { - eventName = 'instantiate'; - attributeKey = '_contract_address'; - } + const eventName = 'instantiate'; + const attributeKey = '_contract_address'; const contractEvents: ContractEvent[] = []; for (const event of txResult.logs[msgIndex].events) {