From 8eba89b35e469493ab096a69c28451311ce748e6 Mon Sep 17 00:00:00 2001 From: summertanh Date: Fri, 18 Dec 2020 18:36:24 +0800 Subject: [PATCH 1/6] change version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38858867..b60a045a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tronweb", - "version": "3.1.0", + "version": "3.2.1", "description": "JavaScript SDK that encapsulates the TRON HTTP API", "main": "dist/TronWeb.node.js", "scripts": { From 413dd6a7551287fdb261fc4d3519e3bd742fbc7d Mon Sep 17 00:00:00 2001 From: summertanh Date: Fri, 18 Dec 2020 18:38:07 +0800 Subject: [PATCH 2/6] Revert "Release/v3.2.0" --- README.md | 5 - package.json | 3 +- src/index.js | 9 +- src/lib/transactionBuilder.js | 8 +- src/lib/ztron.js | 907 --------------------- test/helpers/config.js | 10 +- test/helpers/shieldedUtils.js | 177 ---- test/lib/ztron.test.js | 1443 --------------------------------- webpack.config.js | 3 - 9 files changed, 5 insertions(+), 2560 deletions(-) delete mode 100644 src/lib/ztron.js delete mode 100644 test/helpers/shieldedUtils.js delete mode 100644 test/lib/ztron.test.js diff --git a/README.md b/README.md index 37d11dce..7d05ac0f 100644 --- a/README.md +++ b/README.md @@ -168,11 +168,6 @@ In order to contribute you can ## Recent History -__3.2.0__ -- Support shielded transactions -- Set feeLimit default value as 40 TRX -- The precision in the createToken method supports passing in 0 - __3.1.0__ - Update `elliptic` to the latest version 6.5.3 - Update `ethers` to the latest version 5.0.8 diff --git a/package.json b/package.json index f1a72a39..38858867 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tronweb", - "version": "3.2.0", + "version": "3.1.0", "description": "JavaScript SDK that encapsulates the TRON HTTP API", "main": "dist/TronWeb.node.js", "scripts": { @@ -30,7 +30,6 @@ "eventemitter3": "^3.1.0", "injectpromise": "^1.0.0", "lodash": "^4.17.14", - "redjubjub-js": "^1.0.1", "semver": "^5.6.0", "validator": "^10.7.1" }, diff --git a/src/index.js b/src/index.js index 588da7cb..a0a2fd32 100644 --- a/src/index.js +++ b/src/index.js @@ -12,13 +12,12 @@ import Contract from 'lib/contract'; import Plugin from 'lib/plugin'; import Event from 'lib/event'; import SideChain from 'lib/sidechain'; -import ZTron from 'lib/ztron'; import { keccak256 } from 'utils/ethersUtils'; import { ADDRESS_PREFIX } from 'utils/address'; const DEFAULT_VERSION = '3.5.0'; -const FEE_LIMIT = 40000000; +const FEE_LIMIT = 20000000; export default class TronWeb extends EventEmitter { static providers = providers; @@ -28,7 +27,6 @@ export default class TronWeb extends EventEmitter { static Contract = Contract; static Plugin = Plugin; static Event = Event; - static ZTron = ZTron; static version = version; static utils = utils; @@ -94,14 +92,9 @@ export default class TronWeb extends EventEmitter { if (privateKey) this.setPrivateKey(privateKey); - - // for ztron - this.ztron = new ZTron(this); - this.fullnodeVersion = DEFAULT_VERSION; this.feeLimit = FEE_LIMIT; this.injectPromise = injectpromise(this); - } async getFullnodeVersion() { diff --git a/src/lib/transactionBuilder.js b/src/lib/transactionBuilder.js index 2222a009..be53f3c5 100644 --- a/src/lib/transactionBuilder.js +++ b/src/lib/transactionBuilder.js @@ -857,10 +857,6 @@ export default class TransactionBuilder { } } else parameters = ''; - if(options.shieldedParameter){ - parameters = options.shieldedParameter.replace(/^(0x)/, ''); - } - const args = { contract_address: toHex(contractAddress), owner_address: toHex(issuerAddress), @@ -1039,8 +1035,8 @@ export default class TransactionBuilder { if (utils.isNotNullOrUndefined(voteScore) && (!utils.isInteger(voteScore) || voteScore <= 0)) return callback('voteScore must be a positive integer greater than 0'); - if (utils.isNotNullOrUndefined(precision) && (!utils.isInteger(precision) || precision < 0 || precision > 6)) - return callback('precision must be a positive integer >= 0 and <= 6'); + if (utils.isNotNullOrUndefined(precision) && (!utils.isInteger(precision) || precision <= 0 || precision > 6)) + return callback('precision must be a positive integer > 0 and <= 6'); const data = { owner_address: toHex(issuerAddress), diff --git a/src/lib/ztron.js b/src/lib/ztron.js deleted file mode 100644 index 56cd1ec9..00000000 --- a/src/lib/ztron.js +++ /dev/null @@ -1,907 +0,0 @@ -/* -** for shield transaction -*/ -import TronWeb from 'index'; -import injectpromise from 'injectpromise'; -import Validator from 'paramValidator'; -import utils from 'utils'; -import * as m from 'redjubjub-js'; - -export default class ZTron { - constructor(tronWeb = false) { - if (!tronWeb || !tronWeb instanceof TronWeb) - throw new Error('Expected instance of TronWeb'); - this.tronWeb = tronWeb; - this.injectPromise = injectpromise(this); - this.validator = new Validator(tronWeb); - - [ - 'generate_keys', 'generate_keys_by_sk', 'generate_keys_by_sk_d', 'generate_rk_by_ask', - 'generate_spend_auth_sig', 'verify_spend_auth_sig', 'generate_pk_by_sk', 'generate_binding_sig', - 'verify_binding_sig' - ].forEach(key => { - this[key] = m[key]; - }); - } - - async getExpandedSpendingKey(spendingKey, callback = false) { - if (!callback) { - return this.injectPromise(this.getExpandedSpendingKey, spendingKey); - } - - if (this.validator.notValid([ - { - name: 'spendingKey', - type: 'not-empty-string', - value: spendingKey - } - ], callback)) - return; - - const params = { - value: spendingKey - } - - this.tronWeb.fullNode.request('wallet/getexpandedspendingkey', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async getAkFromAsk(ask, callback = false) { - if (!callback) { - return this.injectPromise(this.getAkFromAsk, ask) - } - - if (this.validator.notValid([ - { - name: 'ask', - type: 'not-empty-string', - value: ask - } - ], callback)) - return; - - const params = { - value: ask - } - - this.tronWeb.fullNode.request('wallet/getakfromask', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async getNkFromNsk(nsk, callback = false) { - if (!callback) { - return this.injectPromise(this.getNkFromNsk, nsk); - } - - if (this.validator.notValid([ - { - name: 'nsk', - type: 'not-empty-string', - value: nsk - } - ], callback)) - return; - - const params = { - value: nsk - } - - this.tronWeb.fullNode.request('wallet/getnkfromnsk', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async getSpendingKey(callback = false) { - if (!callback) { - return this.injectPromise(this.getSpendingKey); - } - - this.tronWeb.fullNode.request('wallet/getspendingkey', null, 'get') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async getDiversifier(callback = false) { - if (!callback) { - return this.injectPromise(this.getDiversifier); - } - - this.tronWeb.fullNode.request('wallet/getdiversifier', null, 'get') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async getIncomingViewingKey(ak, nk, callback = false) { - if (!callback) { - return this.injectPromise(this.getIncomingViewingKey, ak, nk) - } - - if (this.validator.notValid([ - { - name: 'ak', - type: 'not-empty-string', - value: ak - }, - { - name: 'nk', - type: 'not-empty-string', - value: nk - } - ], callback)) - return; - - const params = { - ak, - nk - } - - this.tronWeb.fullNode.request('wallet/getincomingviewingkey', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async getZenPaymentAddress(ivk, d, callback = false) { - if (!callback) { - return this.injectPromise(this.getZenPaymentAddress, ivk, d); - } - - if (this.validator.notValid([ - { - name: 'ivk', - type: 'not-empty-string', - value: ivk - }, - { - name: 'd', - type: 'not-empty-string', - value: d - } - ], callback)) - return; - - const params = { - ivk, - d - } - - this.tronWeb.fullNode.request('wallet/getzenpaymentaddress', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async getRcm(callback = false) { - if (!callback) { - return this.injectPromise(this.getRcm); - } - - this.tronWeb.fullNode.request('wallet/getrcm', null, 'get') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async getNewShieldedAddress(callback = false) { - if (!callback) { - return this.injectPromise(this.getNewShieldedAddress); - } - - this.tronWeb.fullNode.request('wallet/getnewshieldedaddress', null, 'get') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async createSpendAuthSig(ask, txHash, alpha, callback = false) { - if (typeof alpha === 'function') { - callback = alpha; - const rcm = await this.getRcm(); - if (rcm && rcm.value) { - alpha = rcm.value; - } else { - return callback('Failed to generate rcm element') - } - } - if (!callback) { - return this.injectPromise(this.createSpendAuthSig, ask, txHash, alpha); - } - - if (this.validator.notValid([ - { - name: 'ask', - type: 'not-empty-string', - value: ask - }, - { - name: 'txHash', - type: 'not-empty-string', - value: txHash - }, - { - name: 'alpha', - type: 'string', - value: alpha - } - ], callback)) - return; - - const params = { - ask, - alpha, - tx_hash: txHash - } - - this.tronWeb.fullNode.request('wallet/createspendauthsig', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async createMintParams(ovk, fromAmount, shieldedReceives, shieldedTRC20ContractAddress, options = {}, callback = false) { - if (utils.isObject(ovk)) { - options = fromAmount; - callback = shieldedReceives; - fromAmount = ovk.from_amount; - shieldedReceives = ovk.shielded_receives; - shieldedTRC20ContractAddress = ovk.shielded_TRC20_contract_address; - ovk = ovk.ovk; - } - - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.createMintParams, ovk, fromAmount, shieldedReceives, shieldedTRC20ContractAddress, options); - } - if (this.validator.notValid([ - { - name: 'ovk', - type: 'string', - value: ovk - }, - { - name: 'fromAmount', - type: 'string', - value: fromAmount - }, - { - name: 'shieldedReceives', - type: 'notEmptyObject', - value: shieldedReceives - }, - { - name: 'shieldedTRC20ContractAddress', - type: 'address', - value: shieldedTRC20ContractAddress - } - ], callback)) - return; - - const params = { - ovk, - from_amount: fromAmount, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - - this.tronWeb.fullNode.request('wallet/createshieldedcontractparameters', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async createMintParamsWithoutAsk(ovk, fromAmount, shieldedReceives, shieldedTRC20ContractAddress, options = {}, callback = false) { - if (utils.isObject(ovk)) { - options = fromAmount; - callback = shieldedReceives; - fromAmount = ovk.from_amount; - shieldedReceives = ovk.shielded_receives; - shieldedTRC20ContractAddress = ovk.shielded_TRC20_contract_address; - ovk = ovk.ovk; - } - - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.createMintParamsWithoutAsk, ovk, fromAmount, shieldedReceives, shieldedTRC20ContractAddress, options); - } - - if (this.validator.notValid([ - { - name: 'ovk', - type: 'string', - value: ovk - }, - { - name: 'fromAmount', - type: 'string', - value: fromAmount - }, - { - name: 'shieldedReceives', - type: 'notEmptyObject', - value: shieldedReceives - }, - { - name: 'shieldedTRC20ContractAddress', - type: 'address', - value: shieldedTRC20ContractAddress - } - ], callback)) - return; - - const params = { - ovk, - from_amount: fromAmount, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - - this.tronWeb.fullNode.request('wallet/createshieldedcontractparameterswithoutask', params, 'post') - .then(result => callback(null, result)) - .catch(err => callback(err)); - } - - async createTransferParams(ask, nsk, ovk, shieldedSpends, shieldedReceives, shieldedTRC20ContractAddress, options = {}, callback = false) { - if (utils.isObject(ask)) { - options = nsk; - callback = ovk; - nsk = ask.nsk; - ovk = ask.ovk; - shieldedSpends = ask.shielded_spends; - shieldedReceives = ask.shielded_receives; - shieldedTRC20ContractAddress = ask.shielded_TRC20_contract_address; - ask = ask.ask; - } - - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.createTransferParams, ask, nsk, ovk, shieldedSpends, shieldedReceives, shieldedTRC20ContractAddress, options); - } - - if (this.validator.notValid([ - { - name: 'ask', - type: 'string', - value: ask - }, - { - name: 'nsk', - type: 'string', - value: nsk - }, - { - name: 'ovk', - type: 'string', - value: ovk - }, - { - name: 'shieldedSpends', - type: 'array', - value: shieldedSpends - }, - { - name: 'shieldedReceives', - type: 'array', - value: shieldedReceives - }, - { - name: 'shieldedTRC20ContractAddress', - type: 'address', - value: shieldedTRC20ContractAddress - } - ], callback)) - return; - - const params = { - ask, - nsk, - ovk, - shielded_spends: shieldedSpends, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - - this.tronWeb.fullNode.request('wallet/createshieldedcontractparameters', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - - } - - async createTransferParamsWithoutAsk(ak, nsk, ovk, shieldedSpends, shieldedReceives, shieldedTRC20ContractAddress, options = {}, callback = false) { - if (utils.isObject(ak)) { - options = nsk; - callback = ovk; - nsk = ak.nsk; - ovk = ak.ovk; - shieldedSpends = ak.shielded_spends; - shieldedReceives = ak.shielded_receives; - shieldedTRC20ContractAddress = ak.shielded_TRC20_contract_address; - ak = ak.ak; - } - - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.createTransferParamsWithoutAsk, ak, nsk, ovk, shieldedSpends, shieldedReceives, shieldedTRC20ContractAddress, options); - } - - if (this.validator.notValid([ - { - name: 'ak', - type: 'string', - value: ak - }, - { - name: 'nsk', - type: 'string', - value: nsk - }, - { - name: 'ovk', - type: 'string', - value: ovk - }, - { - name: 'shieldedSpends', - type: 'array', - value: shieldedSpends - }, - { - name: 'shieldedReceives', - type: 'array', - value: shieldedReceives - }, - { - name: 'shieldedTRC20ContractAddress', - type: 'address', - value: shieldedTRC20ContractAddress - } - ], callback)) - return; - - const params = { - ak, - nsk, - ovk, - shielded_spends: shieldedSpends, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - - this.tronWeb.fullNode.request('wallet/createshieldedcontractparameterswithoutask', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - - } - - async createBurnParams(ask, nsk, ovk, shieldedSpends, shieldedReceives, transparentToAddress, toAmount, shieldedTRC20ContractAddress, options = {}, callback = false) { - if (utils.isObject(ask)) { - options = nsk; - callback = ovk; - nsk = ask.nsk; - ovk = ask.ovk; - shieldedSpends = ask.shielded_spends; - shieldedReceives = ask.shielded_receives; - transparentToAddress = ask.transparent_to_address; - toAmount = ask.to_amount; - shieldedTRC20ContractAddress = ask.shielded_TRC20_contract_address; - ask = ask.ask; - } - - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.createBurnParams, ask, nsk, ovk, shieldedSpends, shieldedReceives, transparentToAddress, toAmount, shieldedTRC20ContractAddress, options); - } - - if (this.validator.notValid([ - { - name: 'ask', - type: 'string', - value: ask - }, - { - name: 'nsk', - type: 'string', - value: nsk - }, - { - name: 'ovk', - type: 'string', - value: ovk - }, - { - name: 'shieldedSpends', - type: 'array', - value: shieldedSpends - }, - { - name: 'shieldedReceives', - type: 'array', - value: shieldedReceives - }, - { - name: 'transparentToAddress', - type: 'address', - value: transparentToAddress - }, - { - name: 'toAmount', - type: 'string', - value: toAmount - }, - { - name: 'shieldedTRC20ContractAddress', - type: 'address', - value: shieldedTRC20ContractAddress - } - ], callback)) - return; - - const params = { - ask, - nsk, - ovk, - shielded_spends: shieldedSpends, - shielded_receives: shieldedReceives, - transparent_to_address: options && options.visible ? transparentToAddress : this.tronWeb.address.toHex(transparentToAddress), - to_amount: toAmount, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - this.tronWeb.fullNode.request('wallet/createshieldedcontractparameters', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async createBurnParamsWithoutAsk(ak, nsk, ovk, shieldedSpends, shieldedReceives, transparentToAddress, toAmount, shieldedTRC20ContractAddress, options = {}, callback = false) { - if (utils.isObject(ak)) { - options = nsk; - callback = ovk; - nsk = ak.nsk; - ovk = ak.ovk; - shieldedSpends = ak.shielded_spends; - shieldedReceives = ak.shielded_receives; - transparentToAddress = ak.transparent_to_address; - toAmount = ak.to_amount; - shieldedTRC20ContractAddress = ak.shielded_TRC20_contract_address; - ak = ak.ak; - } - - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.createBurnParamsWithoutAsk, ak, nsk, ovk, shieldedSpends, shieldedReceives, transparentToAddress, toAmount, shieldedTRC20ContractAddress, options); - } - - if (this.validator.notValid([ - { - name: 'ak', - type: 'string', - value: ak - }, - { - name: 'nsk', - type: 'string', - value: nsk - }, - { - name: 'ovk', - type: 'string', - value: ovk - }, - { - name: 'shieldedSpends', - type: 'array', - value: shieldedSpends - }, - { - name: 'shieldedReceives', - type: 'array', - value: shieldedReceives - }, - { - name: 'transparentToAddress', - type: 'address', - value: transparentToAddress - }, - { - name: 'toAmount', - type: 'string', - value: toAmount - }, - { - name: 'shieldedTRC20ContractAddress', - type: 'address', - value: shieldedTRC20ContractAddress - } - ], callback)) - return; - - const params = { - ak, - nsk, - ovk, - shielded_spends: shieldedSpends, - shielded_receives: shieldedReceives, - transparent_to_address: this.tronWeb.address.toHex(transparentToAddress), - to_amount: toAmount, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - - this.tronWeb.fullNode.request('wallet/createshieldedcontractparameterswithoutask', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async getTriggerInputForShieldedTRC20Contract(shieldedTRC20Parameters, spendAuthoritySignature, options = {}, callback = false) { - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.getTriggerInputForShieldedTRC20Contract, shieldedTRC20Parameters, spendAuthoritySignature, options); - } - - if (this.validator.notValid([ - { - name: 'shieldedTRC20Parameters', - type: 'notEmptyObject', - value: shieldedTRC20Parameters - }, - { - name: 'spendAuthoritySignature', - type: 'array', - value: spendAuthoritySignature - }, - { - name: 'shieldedTRC20Parameters.spend_description', - type: 'array', - value: shieldedTRC20Parameters.spend_description - }, - { - name: 'shieldedTRC20Parameters.receive_description', - type: 'array', - value: shieldedTRC20Parameters.receive_description - }, - { - name: 'shieldedTRC20Parameters.binding_signature', - type: 'not-empty-string', - value: shieldedTRC20Parameters.binding_signature - }, - { - name: 'shieldedTRC20Parameters.message_hash', - type: 'not-empty-string', - value: shieldedTRC20Parameters.message_hash - }, - { - name: 'shieldedTRC20Parameters.parameter_type', - type: 'not-empty-string', - value: shieldedTRC20Parameters.parameter_type - }, - - ], callback)) - return; - - const params = { - shielded_TRC20_Parameters: shieldedTRC20Parameters, - spend_authority_signature: spendAuthoritySignature, - ...options - } - this.tronWeb.fullNode.request('wallet/gettriggerinputforshieldedtrc20contract', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async isShieldedTRC20ContractNoteSpent(ak, nk, note, position, shieldedTRC20ContractAddress, options = {}, callback = false){ - if (utils.isObject(ak)) { - options = nk; - callback = note; - nk = ak.nk; - note = ak.note; - position = ak.position; - shieldedTRC20ContractAddress = ak.shielded_TRC20_contract_address; - ak = ak.ak; - } - - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.isShieldedTRC20ContractNoteSpent, ak, nk, note, position, shieldedTRC20ContractAddress, options); - } - - if (this.validator.notValid([ - { - name: 'ak', - type: 'string', - value: ak - }, - { - name: 'nk', - type: 'string', - value: nk - }, - { - name: 'note', - type: 'notEmptyObject', - value: note - }, - { - name: 'position', - type: 'integer', - value: position - }, - { - name: 'shieldedTRC20ContractAddress', - type: 'address', - value: shieldedTRC20ContractAddress - } - ], callback)) - return; - - const params = { - ak, - nk, - note, - position, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - - this.tronWeb.fullNode.request('wallet/isshieldedtrc20contractnotespent', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async scanShieldedTRC20NotesByIvk(startBlockIndex, endBlockIndex, ivk, ak, nk, shieldedTRC20ContractAddress, options, callback){ - if (utils.isObject(startBlockIndex)) { - options = endBlockIndex; - callback = ivk; - endBlockIndex = startBlockIndex.end_block_index; - ivk = startBlockIndex.ivk; - ak = startBlockIndex.ak; - nk = startBlockIndex.nk; - shieldedTRC20ContractAddress = startBlockIndex.shielded_TRC20_contract_address; - startBlockIndex = startBlockIndex.start_block_index; - } - - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.scanShieldedTRC20NotesByIvk, startBlockIndex, endBlockIndex, ivk, ak, nk, shieldedTRC20ContractAddress, options); - } - - if (this.validator.notValid([ - { - name: 'startBlockIndex', - type: 'positive-integer', - value: startBlockIndex - }, - { - name: 'endBlockIndex', - type: 'positive-integer', - value: endBlockIndex - }, - { - name: 'ivk', - type: 'string', - value: ivk - }, - { - name: 'ak', - type: 'string', - value: ak - }, - { - name: 'nk', - type: 'string', - value: nk - }, - { - name: 'shieldedTRC20ContractAddress', - type: 'address', - value: shieldedTRC20ContractAddress - } - ], callback)) - return; - - const params = { - ivk, - nk, - ak, - visible: !!options.visible, - start_block_index: startBlockIndex, - end_block_index: endBlockIndex, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - this.tronWeb.fullNode.request('wallet/scanshieldedtrc20notesbyivk', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - - async scanShieldedTRC20NotesByOvk(startBlockIndex, endBlockIndex, ovk, shieldedTRC20ContractAddress, options = {}, callback = false) { - if (utils.isObject(startBlockIndex)) { - options = endBlockIndex; - callback = ovk; - endBlockIndex = startBlockIndex.end_block_index; - ovk = startBlockIndex.ovk; - shieldedTRC20ContractAddress = startBlockIndex.shielded_TRC20_contract_address; - startBlockIndex = startBlockIndex.start_block_index; - } - - if (utils.isFunction(options)) { - callback = options; - options = {}; - } - - if (!callback) { - return this.injectPromise(this.scanShieldedTRC20NotesByOvk, startBlockIndex, endBlockIndex, ovk, shieldedTRC20ContractAddress, options); - } - - if (this.validator.notValid([ - { - name: 'startBlockIndex', - type: 'positive-integer', - value: startBlockIndex - }, - { - name: 'endBlockIndex', - type: 'positive-integer', - value: endBlockIndex - }, - { - name: 'ovk', - type: 'string', - value: ovk - }, - { - name: 'shieldedTRC20ContractAddress', - type: 'address', - value: shieldedTRC20ContractAddress - } - ], callback)) - return; - - const params = { - ovk, - visible: !!options.visible, - start_block_index: startBlockIndex, - end_block_index: endBlockIndex, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - this.tronWeb.fullNode.request('wallet/scanshieldedtrc20notesbyovk', params, 'post') - .then(data => callback(null, data)) - .catch(err => callback(err)); - } - -} diff --git a/test/helpers/config.js b/test/helpers/config.js index 88979286..b7145618 100644 --- a/test/helpers/config.js +++ b/test/helpers/config.js @@ -80,13 +80,5 @@ module.exports = { ADDRESS721_MAPPING: 'TWU8w6qrqb42x9gt5NRGdzXD6xjgzEvnK1', ADDRESS721_MAPPING_HEX: '41e0db2ebd7619fc7d4af7d4cd04515c4f77840d45', - TRC721_ID: 1, - - Z_TRON: { - fullNode: 'https://api.nileex.io/', - solidityNode: 'https://api.nileex.io/', - shieldedAddress: 'TPcKtz5TRfP4xUZSos81RmXB9K2DBqj2iu', - trc20Address: 'TFUD8x3iAZ9dF7NDCGBtSjznemEomE5rP9', - transParentToAddress: 'TRM11TZjzC8Gksria7tpYZvHEWpGW2T68r' - } + TRC721_ID: 1 } diff --git a/test/helpers/shieldedUtils.js b/test/helpers/shieldedUtils.js deleted file mode 100644 index 983743e4..00000000 --- a/test/helpers/shieldedUtils.js +++ /dev/null @@ -1,177 +0,0 @@ - -async function makeAndSendTransaction(tronWeb, contractAddress, functionSelector, options = {}, parameters = [], issuerAddress) { - const transaction = await tronWeb.transactionBuilder.triggerSmartContract( - contractAddress, - functionSelector, - options, - parameters, - tronWeb.address.toHex(issuerAddress) - ); - const signedTransaction = await tronWeb.trx.sign(transaction.transaction, tronWeb.defaultPrivateKey); - return tronWeb.trx.sendRawTransaction(signedTransaction); -} - -function makeShieldedMethodInstance(tronWeb, contractAddress) { - const abiConfig = [{ - "inputs": [{"name": "trc20ContractAddress", "type": "address"}, { - "name": "scalingFactorExponent", - "type": "uint256" - }], "stateMutability": "Nonpayable", "type": "Constructor" - }, { - "inputs": [{"name": "position", "type": "uint256"}, {"name": "cm", "type": "bytes32"}, { - "name": "cv", - "type": "bytes32" - }, {"name": "epk", "type": "bytes32"}, {"name": "c", "type": "bytes32[21]"}], - "name": "BurnNewLeaf", - "type": "Event" - }, { - "inputs": [{"name": "position", "type": "uint256"}, {"name": "cm", "type": "bytes32"}, { - "name": "cv", - "type": "bytes32" - }, {"name": "epk", "type": "bytes32"}, {"name": "c", "type": "bytes32[21]"}], - "name": "MintNewLeaf", - "type": "Event" - }, { - "inputs": [{"name": "nf", "type": "bytes32"}], - "name": "NoteSpent", - "type": "Event" - }, { - "inputs": [{"name": "to", "type": "address"}, {"name": "value", "type": "uint256"}, { - "name": "ciphertext", - "type": "bytes32[3]" - }], "name": "TokenBurn", "type": "Event" - }, { - "inputs": [{"name": "from", "type": "address"}, {"name": "value", "type": "uint256"}], - "name": "TokenMint", - "type": "Event" - }, { - "inputs": [{"name": "position", "type": "uint256"}, {"name": "cm", "type": "bytes32"}, { - "name": "cv", - "type": "bytes32" - }, {"name": "epk", "type": "bytes32"}, {"name": "c", "type": "bytes32[21]"}], - "name": "TransferNewLeaf", - "type": "Event" - }, { - "inputs": [{"name": "input", "type": "bytes32[10]"}, { - "name": "spendAuthoritySignature", - "type": "bytes32[2]" - }, {"name": "rawValue", "type": "uint256"}, { - "name": "bindingSignature", - "type": "bytes32[2]" - }, {"name": "payTo", "type": "address"}, {"name": "burnCipher", "type": "bytes32[3]"}, { - "name": "output", - "type": "bytes32[9][]" - }, {"name": "c", "type": "bytes32[21][]"}], - "name": "burn", - "stateMutability": "Nonpayable", - "type": "Function" - }, { - "outputs": [{"type": "bytes32"}, {"type": "bytes32[32]"}], - "constant": true, - "inputs": [{"name": "position", "type": "uint256"}], - "name": "getPath", - "stateMutability": "View", - "type": "Function" - }, { - "outputs": [{"type": "bytes32"}], - "constant": true, - "name": "latestRoot", - "stateMutability": "View", - "type": "Function" - }, { - "outputs": [{"type": "uint256"}], - "constant": true, - "name": "leafCount", - "stateMutability": "View", - "type": "Function" - }, { - "inputs": [{"name": "rawValue", "type": "uint256"}, { - "name": "output", - "type": "bytes32[9]" - }, {"name": "bindingSignature", "type": "bytes32[2]"}, {"name": "c", "type": "bytes32[21]"}], - "name": "mint", - "stateMutability": "Nonpayable", - "type": "Function" - }, { - "outputs": [{"type": "bytes32"}], - "constant": true, - "inputs": [{"type": "bytes32"}], - "name": "noteCommitment", - "stateMutability": "View", - "type": "Function" - }, { - "outputs": [{"type": "bytes32"}], - "constant": true, - "inputs": [{"type": "bytes32"}], - "name": "nullifiers", - "stateMutability": "View", - "type": "Function" - }, { - "outputs": [{"type": "bytes32"}], - "constant": true, - "inputs": [{"type": "bytes32"}], - "name": "roots", - "stateMutability": "View", - "type": "Function" - }, { - "outputs": [{"type": "uint256"}], - "constant": true, - "name": "scalingFactor", - "stateMutability": "View", - "type": "Function" - }, { - "inputs": [{"name": "input", "type": "bytes32[10][]"}, { - "name": "spendAuthoritySignature", - "type": "bytes32[2][]" - }, {"name": "output", "type": "bytes32[9][]"}, { - "name": "bindingSignature", - "type": "bytes32[2]" - }, {"name": "c", "type": "bytes32[21][]"}], - "name": "transfer", - "stateMutability": "Nonpayable", - "type": "Function" - }, { - "outputs": [{"type": "bytes32"}], - "constant": true, - "inputs": [{"type": "uint256"}], - "name": "tree", - "stateMutability": "View", - "type": "Function" - }] - - return tronWeb.contract(abiConfig, contractAddress) -} - -async function scanShieldedTRC20NotesByIvk(tronWeb, startBlockIndex, endBlockIndex, ivk, ak, nk, visible, shieldedTRC20ContractAddress, options = {}) { - try{ - if (Object.prototype.toString.call(startBlockIndex).slice(8, -1) === 'Object') { - options = endBlockIndex; - endBlockIndex = startBlockIndex.end_block_index; - ivk = startBlockIndex.ivk; - ak = startBlockIndex.ak; - nk = startBlockIndex.nk; - visible = startBlockIndex.visible; - shieldedTRC20ContractAddress = startBlockIndex.shielded_TRC20_contract_address; - startBlockIndex = startBlockIndex.start_block_index; - } - const params = { - ivk, - nk, - ak, - visible: !!visible, - start_block_index: startBlockIndex, - end_block_index: endBlockIndex, - shielded_TRC20_contract_address: options && options.visible ? shieldedTRC20ContractAddress : this.tronWeb.address.toHex(shieldedTRC20ContractAddress), - ...options - } - return tronWeb.fullNode.request('wallet/scanshieldedtrc20notesbyivk', params, 'post') - }catch (e){ - return e - } -} - -module.exports = { - makeShieldedMethodInstance, - makeAndSendTransaction, - scanShieldedTRC20NotesByIvk -} diff --git a/test/lib/ztron.test.js b/test/lib/ztron.test.js deleted file mode 100644 index 625b40fe..00000000 --- a/test/lib/ztron.test.js +++ /dev/null @@ -1,1443 +0,0 @@ -const chai = require('chai'); -const assert = chai.assert; - -const assertThrow = require('../helpers/assertThrow'); -const tronWebBuilder = require('../helpers/tronWebBuilder'); -const wait = require('../helpers/wait'); -const shieldedUtils = require('../helpers/shieldedUtils'); -const {Z_TRON: zTronConfig} = require('../helpers/config'); - - -const TronWeb = tronWebBuilder.TronWeb; - -describe("Tronweb.ztron", function (){ - - let tronWeb; - let noteTxs; //notes - const keysInfo = {}; - const {shieldedAddress, trc20Address} = zTronConfig; - let startBlockIndex = 0, endBlockIndex = 0; - let scalingFactor; - let shieldedSpends; - let shieldedReceives; - let shieldedInfo; - - let methodInstance; - - const narrowValue = 1; - let realCost; - - - before(async function () { - tronWeb = tronWebBuilder.createInstance({ - fullNode: zTronConfig.fullNode, - solidityNode: zTronConfig.solidityNode - }); - methodInstance = shieldedUtils.makeShieldedMethodInstance(tronWeb, shieldedAddress); - scalingFactor = (await methodInstance.scalingFactor().call()).toNumber(); - realCost = tronWeb.BigNumber(narrowValue).multipliedBy(scalingFactor).toFixed(); - shieldedInfo = await tronWeb.ztron.getNewShieldedAddress(); - }); - - describe('#constructor()', function () { - - it('should have been set a full instance in tronWeb', function () { - assert.instanceOf(tronWeb.ztron, TronWeb.ZTron); - }); - - }); - - describe('#getspendingkey', function (){ - it('should get a value', async function (){ - const spendingKeyInfo = await tronWeb.ztron.getSpendingKey(); - assert.ok(spendingKeyInfo.value); - assert.strictEqual(spendingKeyInfo.value.length, 64); - keysInfo.spendingKey = spendingKeyInfo.value - }) - }); - - describe("#getExpandedSpendingKey", function (){ - it('should get spending keys with the spendingKey', async function (){ - const result = await tronWeb.ztron.getExpandedSpendingKey(keysInfo.spendingKey); - assert.ok(result.ask); - assert.ok(result.nsk); - assert.ok(result.ovk); - assert.strictEqual(result.ask.length, 64); - assert.strictEqual(result.nsk.length, 64); - assert.strictEqual(result.ovk.length, 64); - keysInfo.ask = result.ask; - keysInfo.nsk = result.nsk; - keysInfo.ovk = result.ovk; - }) - - it('should throw if The length of spendingKey is not equal to 64', async function (){ - const invalidSpendingKey = keysInfo.spendingKey.slice(0, 54); - const result = await tronWeb.ztron.getExpandedSpendingKey(invalidSpendingKey); - assert.ok(result.Error.indexOf('should be 64') !== -1) - }) - - it('should throw if spendingKey is null.', async function (){ - await assertThrow( - tronWeb.ztron.getExpandedSpendingKey(null), - 'Invalid spendingKey provided' - ) - }) - - it('should throw if spendingKey is undefined.', async function (){ - await assertThrow( - tronWeb.ztron.getExpandedSpendingKey(undefined), - 'Invalid spendingKey provided' - ) - }) - - it('should throw if spendingKey is empty string.', async function (){ - await assertThrow( - tronWeb.ztron.getExpandedSpendingKey(''), - 'Invalid spendingKey provided' - ) - }) - - }) - - describe("#getAkFromAsk", function (){ - - it('should get ak value with ask', async function (){ - const result = await tronWeb.ztron.getAkFromAsk(keysInfo.ask); - assert.ok(result.value); - assert.strictEqual(result.value.length, 64); - keysInfo.ak = result.value; - }) - - it('should throw if The length of ask is not equal to 64', async function (){ - const invalidAsk = keysInfo.ask.slice(0, 54) - const result = await tronWeb.ztron.getAkFromAsk(invalidAsk); - assert.ok(result.Error.indexOf('should be 64') !== -1) - }) - - it('should throw if ask is null.', async function (){ - await assertThrow( - tronWeb.ztron.getAkFromAsk(null), - 'Invalid ask provided' - ) - }) - - it('should throw if ask is undefined.', async function (){ - await assertThrow( - tronWeb.ztron.getAkFromAsk(undefined), - 'Invalid ask provided' - ) - }) - - it('should throw if ask is empty string.', async function (){ - await assertThrow( - tronWeb.ztron.getAkFromAsk(''), - 'Invalid ask provided' - ) - }) - }) - - describe("#getNkFromNsk", function (){ - - it('should get nk value with nsk', async function (){ - const result = await tronWeb.ztron.getNkFromNsk(keysInfo.nsk); - assert.ok(result.value); - assert.strictEqual(result.value.length, 64); - keysInfo.nk = result.value; - }) - - it('should throw if The length of nsk is not equal to 64', async function (){ - const invalidNsk = keysInfo.nsk.slice(0, 54); - const result = await tronWeb.ztron.getNkFromNsk(invalidNsk); - assert.ok(result.Error.indexOf('should be 64') !== -1) - }) - - it('should throw if nsk is null.', async function (){ - await assertThrow( - tronWeb.ztron.getNkFromNsk(null), - 'Invalid nsk provided' - ) - }) - - it('should throw if nsk is undefined.', async function (){ - await assertThrow( - tronWeb.ztron.getNkFromNsk(undefined), - 'Invalid nsk provided' - ) - }) - - it('should throw if nsk is empty string.', async function (){ - await assertThrow( - tronWeb.ztron.getNkFromNsk(''), - 'Invalid nsk provided' - ) - }) - }) - - describe("#getDiversifier", function (){ - it('should get a value', async function (){ - const result = await tronWeb.ztron.getDiversifier(); - assert.ok(result.d); - keysInfo.d = result.d - }) - }) - - describe("#getIncomingViewingKey", function (){ - it('should get ivk', async function (){ - const result = await tronWeb.ztron.getIncomingViewingKey(keysInfo.ak, keysInfo.nk); - assert.ok(result.ivk); - assert.strictEqual(result.ivk.length, 64); - keysInfo.ivk = result.ivk; - }) - - it('should throw if ak is empty string', async function (){ - await assertThrow( - tronWeb.ztron.getIncomingViewingKey('', keysInfo.nk), - 'Invalid ak provided' - ) - }) - - it('should throw if ak provides an irregular length', async function (){ - const result = await tronWeb.ztron.getIncomingViewingKey(keysInfo.ak.slice(0, 10), keysInfo.nk); - assert.ok(result.Error.indexOf('param length must be 32') !== -1) - }) - - - it('should throw if nk is empty string', async function (){ - await assertThrow( - tronWeb.ztron.getIncomingViewingKey(keysInfo.ak, ''), - 'Invalid nk provided' - ) - }) - - it('should throw if nk provides an irregular length', async function (){ - const result = await tronWeb.ztron.getIncomingViewingKey(keysInfo.ak, keysInfo.nk.slice(0, 10)); - assert.ok(result.Error.indexOf('param length must be 32') !== -1) - }) - }) - - describe("#getZenPaymentAddress", function (){ - it('should get paymentAddress', async function (){ - const result = await tronWeb.ztron.getZenPaymentAddress(keysInfo.ivk, keysInfo.d); - assert.ok(result.payment_address && result.pkD); - keysInfo.pkD = result.pkD; - keysInfo.payment_address = result.payment_address; - }) - - it('should throw if The length of ivk does not match the rules', async function (){ - const result = await tronWeb.ztron.getZenPaymentAddress(keysInfo.ivk.slice(0, 10), keysInfo.d); - assert.ok(result.Error.indexOf('param length must be 32') !== -1); - }) - - it('should throw if an invalid d is passed', async function (){ - const result = await tronWeb.ztron.getZenPaymentAddress(keysInfo.ivk, '52a2416b346f416ed75049'); - assert.ok(result.Error.indexOf('d is not valid') !== -1); - }) - - it('should throw if ivk is an empty string', async function (){ - await assertThrow( - tronWeb.ztron.getZenPaymentAddress('', keysInfo.d), - 'Invalid ivk provided' - ) - }) - - it('should throw if d is an empty string', async function (){ - await assertThrow( - tronWeb.ztron.getZenPaymentAddress(keysInfo.ivk, ''), - 'Invalid d provided' - ) - }) - }) - - describe("#getRcm", function (){ - it('should get rcm value', async function (){ - const result = await tronWeb.ztron.getRcm(); - assert.ok(result.value); - assert.strictEqual(result.value.length, 64); - keysInfo.rcm = result.value - }) - }) - - describe("#getNewShieldedAddress", function (){ - it('should get shieldedAddress value', async function () { - const result = await tronWeb.ztron.getNewShieldedAddress(); - assert.ok(result.ask && result.sk && result.nsk && result.ovk - && result.ak && result.nk && result.ivk && result.d && result.pkD && result.payment_address); - }) - }) - - describe("#createMintParams", function (){ - - it('should get mintParams with ovk is object', async function (){ - const startBlockInfo = await tronWeb.trx.getCurrentBlock() - - for(let i = 0; i < 4; i++){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const params = { - from_amount: realCost, - shielded_receives: { - note: { - value: narrowValue, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - }, - shielded_TRC20_contract_address: shieldedAddress, - ovk: shieldedInfo.ovk - } - - const result = await tronWeb.ztron.createMintParams(params); - assert.ok(result && result.trigger_contract_input); - - const address = tronWeb.defaultAddress.base58; - //approve - await shieldedUtils.makeAndSendTransaction(tronWeb, trc20Address, 'approve(address,uint256)', {}, - [{type: 'address', value: shieldedAddress},{type: 'uint256', value: narrowValue * scalingFactor}], address) - - const options = { - shieldedParameter: result.trigger_contract_input - } - await shieldedUtils.makeAndSendTransaction(tronWeb, shieldedAddress, 'mint(uint256,bytes32[9],bytes32[2],bytes32[21])', options, [], address); - - } - // const endBlockInfo = await tronWeb.trx.getCurrentBlock(); - startBlockIndex = startBlockInfo.block_header.raw_data.number; - endBlockIndex = startBlockIndex + 999; - }) - - it('should get mintParams with Expanded parameters', async function(){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const shieldedReceives = { - note: { - value: narrowValue, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const result = await tronWeb.ztron.createMintParams(shieldedInfo.ovk, realCost, shieldedReceives, shieldedAddress); - assert.ok(result && result.trigger_contract_input); - }) - - it('should get mintParams with options param', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const shieldedReceives = { - note: { - value: narrowValue, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const options = { - visible: false, - from_amount: tronWeb.BigNumber(10).multipliedBy(scalingFactor).toFixed(), - shielded_receives: { - note: { - value: 10, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - } - const result = await tronWeb.ztron.createMintParams(shieldedInfo.ovk, realCost, shieldedReceives, shieldedAddress, options); - assert.ok(result && result.trigger_contract_input); - }) - - it('should throw if avk not a string', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const invalidOvk = 1111; - const shieldedReceives = { - note: { - value: 100, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const fromAmount = '1000'; - await assertThrow( - tronWeb.ztron.createMintParams(invalidOvk, fromAmount, shieldedReceives, shieldedAddress), - 'Invalid ovk provided' - ) - await assertThrow( - tronWeb.ztron.createMintParams({ - from_amount: fromAmount, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: shieldedAddress, - ovk: invalidOvk - }), - 'Invalid ovk provided' - ) - }) - - it('should throw if fromAmount not a string', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const ovk = shieldedInfo.ovk; - const shieldedReceives = { - note: { - value: 100, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const invalidFromAmount = 1000; - await assertThrow( - tronWeb.ztron.createMintParams(ovk, invalidFromAmount, shieldedReceives, shieldedAddress), - 'Invalid fromAmount provided' - ) - await assertThrow( - tronWeb.ztron.createMintParams({ - from_amount: invalidFromAmount, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: shieldedAddress, - ovk: ovk - }), - 'Invalid fromAmount provided' - ) - }) - - it('should throw if shieldedReceives is an empty Object', async function (){ - const ovk = shieldedInfo.ovk; - const shieldedReceivesEmpty = {}; - const fromAmount = '1000'; - await assertThrow( - tronWeb.ztron.createMintParams(ovk, fromAmount, shieldedReceivesEmpty, shieldedAddress), - 'Invalid shieldedReceives provided' - ) - await assertThrow( - tronWeb.ztron.createMintParams({ - from_amount: fromAmount, - shielded_receives: null, - shielded_TRC20_contract_address: shieldedAddress, - ovk: ovk - }), - 'Invalid shieldedReceives provided' - ) - }) - - it('should throw if shieldedTRC20ContractAddress not an address', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const ovk = shieldedInfo.ovk; - const shieldedReceives = { - note: { - value: 100, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const fromAmount = '1000'; - const invalidAddress = shieldedAddress.slice(0, shieldedAddress.length - 3); - await assertThrow( - tronWeb.ztron.createMintParams(ovk, fromAmount, shieldedReceives, invalidAddress), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - await assertThrow( - tronWeb.ztron.createMintParams({ - from_amount: fromAmount, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: invalidAddress, - ovk: ovk - }), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - }) - }) - - describe("#createMintParamsWithoutAsk", function (){ - - it('should get mintParams with ovk is object', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const params = { - from_amount: '1000', - shielded_receives: { - note: { - value: 100, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - }, - shielded_TRC20_contract_address: shieldedAddress, - ovk: shieldedInfo.ovk - } - - const result = await tronWeb.ztron.createMintParamsWithoutAsk(params); - assert.ok(result && result.trigger_contract_input); - }) - - it('should get mintParams with Expanded parameters', async function(){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const shieldedReceives = { - note: { - value: 100, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const result = await tronWeb.ztron.createMintParamsWithoutAsk(shieldedInfo.ovk, '1000', shieldedReceives, shieldedAddress); - assert.ok(result && result.trigger_contract_input); - }) - - it('should get mintParams with options param', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const shieldedReceives = { - note: { - value: 100, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const options = { - visible: false, - from_amount: '10000', - shielded_receives: { - note: { - value: 1000, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - } - const result = await tronWeb.ztron.createMintParamsWithoutAsk(shieldedInfo.ovk, '1000', shieldedReceives, shieldedAddress, options); - assert.ok(result && result.trigger_contract_input); - }) - - it('should throw if avk not a string', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const invalidOvk = 1111; - const shieldedReceives = { - note: { - value: 100, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const fromAmount = '1000'; - await assertThrow( - tronWeb.ztron.createMintParamsWithoutAsk(invalidOvk, fromAmount, shieldedReceives, shieldedAddress), - 'Invalid ovk provided' - ) - await assertThrow( - tronWeb.ztron.createMintParamsWithoutAsk({ - from_amount: fromAmount, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: shieldedAddress, - ovk: invalidOvk - }), - 'Invalid ovk provided' - ) - }) - - it('should throw if fromAmount not a string', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const ovk = shieldedInfo.ovk; - const shieldedReceives = { - note: { - value: 100, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const invalidFromAmount = 1000; - await assertThrow( - tronWeb.ztron.createMintParamsWithoutAsk(ovk, invalidFromAmount, shieldedReceives, shieldedAddress), - 'Invalid fromAmount provided' - ) - await assertThrow( - tronWeb.ztron.createMintParamsWithoutAsk({ - from_amount: invalidFromAmount, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: shieldedAddress, - ovk: ovk - }), - 'Invalid fromAmount provided' - ) - }) - - it('should throw if shieldedReceives is an empty Object', async function (){ - const ovk = shieldedInfo.ovk; - const shieldedReceivesEmpty = {}; - const fromAmount = '1000'; - await assertThrow( - tronWeb.ztron.createMintParamsWithoutAsk(ovk, fromAmount, shieldedReceivesEmpty, shieldedAddress), - 'Invalid shieldedReceives provided' - ) - await assertThrow( - tronWeb.ztron.createMintParamsWithoutAsk({ - from_amount: fromAmount, - shielded_receives: null, - shielded_TRC20_contract_address: shieldedAddress, - ovk: ovk - }), - 'Invalid shieldedReceives provided' - ) - }) - - it('should throw if shieldedTRC20ContractAddress not an address', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const ovk = shieldedInfo.ovk; - const shieldedReceives = { - note: { - value: 100, - payment_address: shieldedInfo.payment_address, - rcm: rcmInfo.value - } - } - const fromAmount = '1000'; - const invalidAddress = shieldedAddress.slice(0, shieldedAddress.length - 3); - await assertThrow( - tronWeb.ztron.createMintParamsWithoutAsk(ovk, fromAmount, shieldedReceives, invalidAddress), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - await assertThrow( - tronWeb.ztron.createMintParamsWithoutAsk({ - from_amount: fromAmount, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: invalidAddress, - ovk: ovk - }), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - }) - - }) - - describe("#scanShieldedTRC20NotesByIvk", function (){ - const options = { - visible: true - } - it('should get noteTxs with startBlockIndex is object', async function (){ - await wait(10) - const params = { - "start_block_index": startBlockIndex, - "end_block_index": endBlockIndex, - "shielded_TRC20_contract_address": shieldedAddress, - "ivk": shieldedInfo.ivk, - "ak": shieldedInfo.ak, - "nk": shieldedInfo.nk, - } - const result = await tronWeb.ztron.scanShieldedTRC20NotesByIvk(params, options); - assert.ok(result && result.noteTxs && result.noteTxs.length > 0); - noteTxs = result.noteTxs - }) - - it('should get noteTxs with The parameters are expanded', async function (){ - const result = await tronWeb.ztron.scanShieldedTRC20NotesByIvk(startBlockIndex, endBlockIndex, shieldedInfo.ivk, - shieldedInfo.ak, shieldedInfo.nk, shieldedAddress, options); - assert.ok(result && result.noteTxs && result.noteTxs.length > 0); - }) - - it('should throw if startBlockIndex not a positive-integer', async function (){ - const invalidStartBlockIndex = -10; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByIvk(invalidStartBlockIndex, endBlockIndex, shieldedInfo.ivk, - shieldedInfo.ak, shieldedInfo.nk, shieldedAddress, options), - 'startBlockIndex must be a positive integer' - ) - const stringStartBlockIndex = '1001'; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByIvk(stringStartBlockIndex, endBlockIndex, shieldedInfo.ivk, - shieldedInfo.ak, shieldedInfo.nk, shieldedAddress, options), - 'startBlockIndex must be a positive integer' - ) - }) - - it('should throw if endBlockIndex not a positive-integer', async function (){ - const invalidEndBlockIndex = -10; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByIvk(startBlockIndex, invalidEndBlockIndex, shieldedInfo.ivk, - shieldedInfo.ak, shieldedInfo.nk, shieldedAddress, options), - 'endBlockIndex must be a positive integer' - ) - const stringEndBlockIndex = '1001'; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByIvk(startBlockIndex, stringEndBlockIndex, shieldedInfo.ivk, - shieldedInfo.ak, shieldedInfo.nk, shieldedAddress, options), - 'endBlockIndex must be a positive integer' - ) - }) - - it('should throw if ivk|ak|nk is not a string', async function (){ - const invalidIvk = 1111; - const invalidAk = 1111; - const invalidNk = 1111; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByIvk(startBlockIndex, endBlockIndex, invalidIvk, - shieldedInfo.ak, shieldedInfo.nk, shieldedAddress, options), - 'Invalid ivk provided' - ) - - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByIvk(startBlockIndex, endBlockIndex, shieldedInfo.ivk, - invalidAk, shieldedInfo.nk, shieldedAddress, options), - 'Invalid ak provided' - ) - - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByIvk(startBlockIndex, endBlockIndex, shieldedInfo.ivk, - shieldedInfo.ak, invalidNk, shieldedAddress, options), - 'Invalid nk provided' - ) - }) - - it('should throw if shieldedTRC20ContractAddress is not an address', async function (){ - const invalidShieldedTRC20ContractAddress = shieldedAddress.slice(0, 10); - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByIvk(startBlockIndex, endBlockIndex, shieldedInfo.ivk, - shieldedInfo.ak, shieldedInfo.nk, invalidShieldedTRC20ContractAddress, options), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - }) - - after(async () => { - const pathInfo = await methodInstance.getPath(noteTxs[0].position).call(); - shieldedSpends = [{ - "note": noteTxs[0].note, - "alpha": (await tronWeb.ztron.getRcm()).value, - "root": pathInfo[0].replace('0x', ''), - "path": pathInfo[1].map(v => v.replace('0x', '')).join(''), - "pos": noteTxs[0].position - }]; - shieldedReceives = [{ - note: { - value: 1, - payment_address: shieldedInfo.payment_address, - rcm: ( await tronWeb.ztron.getRcm()).value - } - }] - }) - }) - - describe("#createTransferParams", function (){ - before(async ()=>{ - - }) - it('should get transferParams with ask is object', async function (){ - const params = { - shielded_spends: shieldedSpends, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: shieldedAddress, - ovk: shieldedInfo.ovk, - ask: shieldedInfo.ask, - nsk: shieldedInfo.nsk - } - const result = await tronWeb.ztron.createTransferParams(params); - assert.ok(result && result.trigger_contract_input); - - const options = { - shieldedParameter: result.trigger_contract_input - } - const transactionResult = await shieldedUtils.makeAndSendTransaction(tronWeb, shieldedAddress, - 'transfer(bytes32[10][],bytes32[2][],bytes32[9][],bytes32[2],bytes32[21][])', options, [], tronWeb.defaultAddress.base58); - assert.ok(transactionResult && transactionResult.result); - }) - - it('should get transferParams with Expanded parameters', async function(){ - const result = await tronWeb.ztron.createTransferParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, shieldedReceives, shieldedAddress, {}); - assert.ok(result && result.trigger_contract_input); - }) - - it('should throw if ask|nsk|ovk not a string', async function (){ - const invalidAsk = 1111; - const invalidNsk = 1111; - const invalidOvk = 1111; - - await assertThrow( - tronWeb.ztron.createTransferParams(invalidAsk, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, shieldedReceives, shieldedAddress, {}), - 'Invalid ask provided' - ) - await assertThrow( - tronWeb.ztron.createTransferParams({ - shielded_spends: shieldedSpends, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: shieldedAddress, - ovk: shieldedInfo.ovk, - ask: invalidAsk, - nsk: shieldedInfo.nsk - }), - 'Invalid ask provided' - ) - - await assertThrow( - tronWeb.ztron.createTransferParams(shieldedInfo.ask, invalidNsk, shieldedInfo.ovk, - shieldedSpends, shieldedReceives, shieldedAddress, {}), - 'Invalid nsk provided' - ) - - await assertThrow( - tronWeb.ztron.createTransferParams(shieldedInfo.ask, shieldedInfo.nsk, invalidOvk, - shieldedSpends, shieldedReceives, shieldedAddress, {}), - 'Invalid ovk provided' - ) - }) - - it('should throw if shieldedSpends|shieldedReceives not an array', async function (){ - const invalidShieldedSpends = {}; - const invalidShieldedReceives = {}; - await assertThrow( - tronWeb.ztron.createTransferParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - invalidShieldedSpends, shieldedReceives, shieldedAddress, {}), - 'Invalid shieldedSpends provided' - ) - - await assertThrow( - tronWeb.ztron.createTransferParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, invalidShieldedReceives, shieldedAddress, {}), - 'Invalid shieldedReceives provided' - ) - }) - - it('should throw if shieldedTRC20ContractAddress is not an address', async function (){ - const invalidShieldedTRC20ContractAddress = shieldedAddress.slice(0, 10); - await assertThrow( - tronWeb.ztron.createTransferParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, shieldedReceives, invalidShieldedTRC20ContractAddress, {}), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - }) - }) - - describe("#createTransferParamsWithoutAsk chain", function (){ - let transferParamsResult; - let spendAuthoritySignature; - let transferTriggerContractInput; - describe('#createTransferParamsWithoutAsk', function (){ - it('should get transferParams without ask, ak is an object', async function (){ - const params = { - shielded_spends: shieldedSpends, - shielded_receives: shieldedReceives, - shielded_TRC20_contract_address: shieldedAddress, - ovk: shieldedInfo.ovk, - ak: shieldedInfo.ak, - nsk: shieldedInfo.nsk - } - const result = await tronWeb.ztron.createTransferParamsWithoutAsk(params); - assert.ok(result && result.binding_signature && result.message_hash); - transferParamsResult = result; - }) - - it('should get transferParams without ask, The parameters are expanded', async function (){ - const result = await tronWeb.ztron.createTransferParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, shieldedReceives, shieldedAddress, {}); - assert.ok(result && result.binding_signature && result.message_hash); - }) - - it('should trow if ak|nsk|ovk is not a string', async function (){ - const invalidAk = 1111; - const invalidNsk = 1111; - const invalidOvk = 1111; - - await assertThrow( - tronWeb.ztron.createTransferParamsWithoutAsk(invalidAk, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, shieldedReceives, shieldedAddress, {}), - 'Invalid ak provided' - ) - - await assertThrow( - tronWeb.ztron.createTransferParamsWithoutAsk(shieldedInfo.ak, invalidNsk, shieldedInfo.ovk, - shieldedSpends, shieldedReceives, shieldedAddress, {}), - 'Invalid nsk provided' - ) - - await assertThrow( - tronWeb.ztron.createTransferParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, invalidOvk, - shieldedSpends, shieldedReceives, shieldedAddress, {}), - 'Invalid ovk provided' - ) - }) - - it('should throw if shieldedSpends|shieldedReceives not an array', async function (){ - const invalidShieldedSpends = {}; - const invalidShieldedReceives = {}; - await assertThrow( - tronWeb.ztron.createTransferParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, shieldedInfo.ovk, - invalidShieldedSpends, shieldedReceives, shieldedAddress, {}), - 'Invalid shieldedSpends provided' - ) - - await assertThrow( - tronWeb.ztron.createTransferParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, invalidShieldedReceives, shieldedAddress, {}), - 'Invalid shieldedReceives provided' - ) - }) - - it('should throw if shieldedTRC20ContractAddress is not an address', async function (){ - const invalidShieldedTRC20ContractAddress = shieldedAddress.slice(0, 10); - await assertThrow( - tronWeb.ztron.createTransferParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, shieldedReceives, invalidShieldedTRC20ContractAddress, {}), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - }) - }) - - describe("#createSpendAuthSig", async function (){ - let txHash; - let alpha; - before(async () => { - txHash = transferParamsResult.message_hash; - alpha = (await tronWeb.ztron.getRcm()).value; - }) - it('should get a value with txHash', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const result = await tronWeb.ztron.createSpendAuthSig(shieldedInfo.ask, txHash, rcmInfo.value); - assert.ok(result && result.value); - spendAuthoritySignature = result.value; - }) - - it('should throw if ask is an empty string or not a string', async function (){ - const askNotString = 1111; - const askEmptyString = ''; - await assertThrow( - tronWeb.ztron.createSpendAuthSig(askNotString, txHash, alpha), - 'Invalid ask provided' - ) - - await assertThrow( - tronWeb.ztron.createSpendAuthSig(askEmptyString, txHash, alpha), - 'Invalid ask provided' - ) - }) - - it('should throw if txHash is an empty string or not a string', async function (){ - const txHashNotString = 1111; - const txHashEmptyString = ''; - await assertThrow( - tronWeb.ztron.createSpendAuthSig(shieldedInfo.ask, txHashNotString, alpha), - 'Invalid txHash provided' - ) - - await assertThrow( - tronWeb.ztron.createSpendAuthSig(shieldedInfo.ask, txHashEmptyString, alpha), - 'Invalid txHash provided' - ) - }) - - it('should throw if alpha is not a string', async function (){ - const alphaNotString = 1111; - await assertThrow( - tronWeb.ztron.createSpendAuthSig(shieldedInfo.ask, txHash, alphaNotString), - 'Invalid alpha provided' - ) - }) - }) - - describe("#getTriggerInputForShieldedTRC20Contract", function (){ - const shieldedTRC20Parameters = {}; - let spendAuthoritySignatureArray; - - before(async ()=> { - Object.assign(shieldedTRC20Parameters, transferParamsResult); - spendAuthoritySignatureArray = [{ - value: spendAuthoritySignature - }]; - }) - - it('it should return transfer trigger_contract_input value', async function (){ - const result = await tronWeb.ztron.getTriggerInputForShieldedTRC20Contract(shieldedTRC20Parameters, spendAuthoritySignatureArray); - assert.ok(result && result.value) - transferTriggerContractInput = result.value; - }) - - it('should throw if shieldedTRC20Parameters is not an object', async function (){ - const invalidShieldedTRC20Parameters = []; - await assertThrow( - tronWeb.ztron.getTriggerInputForShieldedTRC20Contract(invalidShieldedTRC20Parameters, spendAuthoritySignatureArray), - 'Invalid shieldedTRC20Parameters provided' - ) - }) - - it('should throw if spendAuthoritySignature is not an array', async function (){ - const invalidSpendAuthoritySignature = {}; - await assertThrow( - tronWeb.ztron.getTriggerInputForShieldedTRC20Contract(shieldedTRC20Parameters, invalidSpendAuthoritySignature), - 'Invalid spendAuthoritySignature provided' - ) - }) - - it('should throw if shieldedTRC20Parameters.spend_description is not an array', async function (){ - const invalidShieldedTRC20Parameters = { - spend_description: {} - }; - await assertThrow( - tronWeb.ztron.getTriggerInputForShieldedTRC20Contract(Object.assign({}, shieldedTRC20Parameters, invalidShieldedTRC20Parameters), spendAuthoritySignatureArray), - 'Invalid shieldedTRC20Parameters.spend_description provided' - ) - }) - - it('should throw if shieldedTRC20Parameters.receive_description is not an array', async function (){ - const invalidShieldedTRC20Parameters = { - receive_description: {} - }; - await assertThrow( - tronWeb.ztron.getTriggerInputForShieldedTRC20Contract(Object.assign({}, shieldedTRC20Parameters, invalidShieldedTRC20Parameters), spendAuthoritySignatureArray), - 'Invalid shieldedTRC20Parameters.receive_description provided' - ) - }) - - it('should throw if shieldedTRC20Parameters.binding_signature is not a string', async function (){ - const invalidShieldedTRC20Parameters = { - binding_signature: 1111, - }; - await assertThrow( - tronWeb.ztron.getTriggerInputForShieldedTRC20Contract(Object.assign({}, shieldedTRC20Parameters, invalidShieldedTRC20Parameters), spendAuthoritySignatureArray), - 'Invalid shieldedTRC20Parameters.binding_signature provided' - ) - }) - - it('should throw if shieldedTRC20Parameters.message_hash is not a string', async function (){ - const invalidShieldedTRC20Parameters = { - message_hash: 1111, - }; - await assertThrow( - tronWeb.ztron.getTriggerInputForShieldedTRC20Contract(Object.assign({}, shieldedTRC20Parameters, invalidShieldedTRC20Parameters), spendAuthoritySignatureArray), - 'Invalid shieldedTRC20Parameters.message_hash provided' - ) - }) - - it('should throw if shieldedTRC20Parameters.parameter_type is not a string', async function (){ - const invalidShieldedTRC20Parameters = { - parameter_type: 1111, - }; - await assertThrow( - tronWeb.ztron.getTriggerInputForShieldedTRC20Contract(Object.assign({}, shieldedTRC20Parameters, invalidShieldedTRC20Parameters), spendAuthoritySignatureArray), - 'Invalid shieldedTRC20Parameters.parameter_type provided' - ) - }) - }) - - }) - - describe("#createBurnParams", function (){ - let burnShieldedReceives = []; - let toAmount; - let burnShieldedSpends; - const transParentToAddress = zTronConfig.transParentToAddress; - - before(async () => { - const pathInfo = await methodInstance.getPath(noteTxs[1].position).call(); - burnShieldedSpends = [{ - "note": noteTxs[1].note, - "alpha": (await tronWeb.ztron.getRcm()).value, - "root": pathInfo[0].replace('0x', ''), - "path": pathInfo[1].map(v => v.replace('0x', '')).join(''), - "pos": noteTxs[1].position - }]; - - Object.assign(burnShieldedReceives, shieldedReceives); - burnShieldedReceives[0].note.value = 0; - toAmount = tronWeb.BigNumber(burnShieldedSpends[0].note.value).minus(burnShieldedReceives[0].note.value).multipliedBy(scalingFactor).toFixed() - }) - - it('should get burnParams with ask is object', async function (){ - let params = { - shielded_spends: burnShieldedSpends, - shielded_receives: burnShieldedReceives, - shielded_TRC20_contract_address: shieldedAddress, - ovk: shieldedInfo.ovk, - ask: shieldedInfo.ask, - nsk: shieldedInfo.nsk, - to_amount: toAmount, - transparent_to_address: transParentToAddress - } - - const result = await tronWeb.ztron.createBurnParams(params); - assert.ok(result && result.trigger_contract_input); - - const options = { - shieldedParameter: result.trigger_contract_input - } - const transactionResult = await shieldedUtils.makeAndSendTransaction(tronWeb, shieldedAddress, - 'burn(bytes32[10],bytes32[2],uint256,bytes32[2],address,bytes32[3],bytes32[9][],bytes32[21][])', options, [], tronWeb.defaultAddress.base58); - assert.ok(transactionResult && transactionResult.result); - }) - - it('should get burnParams with Expanded parameters', async function(){ - const result = await tronWeb.ztron.createBurnParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - burnShieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress); - assert.ok(result && result.trigger_contract_input); - }) - - it('should throw if ask|nsk|ovk not a string', async function (){ - const invalidAsk = 1111; - const invalidNsk = 1111; - const invalidOvk = 1111; - - await assertThrow( - tronWeb.ztron.createBurnParams(invalidAsk, shieldedInfo.nsk, shieldedInfo.ovk, - burnShieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid ask provided' - ) - - await assertThrow( - tronWeb.ztron.createBurnParams(shieldedInfo.ask, invalidNsk, shieldedInfo.ovk, - burnShieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid nsk provided' - ) - - await assertThrow( - tronWeb.ztron.createBurnParams(shieldedInfo.ask, shieldedInfo.nsk, invalidOvk, - burnShieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid ovk provided' - ) - }) - - it('should throw if shieldedSpends|shieldedReceives not an array', async function (){ - const invalidShieldedSpends = {}; - const invalidShieldedReceives = {}; - await assertThrow( - tronWeb.ztron.createBurnParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - invalidShieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid shieldedSpends provided' - ) - - await assertThrow( - tronWeb.ztron.createBurnParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - burnShieldedSpends, invalidShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid shieldedReceives provided' - ) - }) - - it('should throw if toAmount is not a string', async function (){ - const invalidToAmount = 10; - await assertThrow( - tronWeb.ztron.createBurnParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - burnShieldedSpends, burnShieldedReceives, transParentToAddress, invalidToAmount, shieldedAddress), - 'Invalid toAmount provided' - ) - }) - - it('should throw if transparentToAddress is not an address', async function (){ - const invalidTransparentToAddress = transParentToAddress.slice(0, 10); - await assertThrow( - tronWeb.ztron.createBurnParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - burnShieldedSpends, burnShieldedReceives, invalidTransparentToAddress, toAmount, shieldedAddress), - 'Invalid transparentToAddress address provided' - ) - }) - - it('should throw if shieldedTRC20ContractAddress is not an address', async function (){ - const invalidShieldedTRC20ContractAddress = shieldedAddress.slice(0, 10); - await assertThrow( - tronWeb.ztron.createBurnParams(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - burnShieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, invalidShieldedTRC20ContractAddress), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - }) - - - - }) - - describe("#createBurnParamsWithoutAsk chain", function (){ - let burnParamsResult; - let spendAuthoritySignature; - let burnTriggerContractInput; - - let burnShieldedReceives = []; - let toAmount; - const transParentToAddress = zTronConfig.transParentToAddress; - - before(async () => { - Object.assign(burnShieldedReceives, shieldedReceives); - burnShieldedReceives[0].note.value = 0; - toAmount = tronWeb.BigNumber(shieldedSpends[0].note.value).minus(burnShieldedReceives[0].note.value).multipliedBy(scalingFactor).toFixed() - }) - - describe('#createBurnParamsWithoutAsk', function (){ - it('should get burnParams without ask, ak is an object', async function (){ - let params = { - shielded_spends: shieldedSpends, - shielded_receives: burnShieldedReceives, - shielded_TRC20_contract_address: shieldedAddress, - ovk: shieldedInfo.ovk, - ak: shieldedInfo.ak, - nsk: shieldedInfo.nsk, - to_amount: toAmount, - transparent_to_address: transParentToAddress - } - const result = await tronWeb.ztron.createBurnParamsWithoutAsk(params); - assert.ok(result && result.binding_signature && result.message_hash); - burnParamsResult = result; - }) - - it('should get transferParams without ask, The parameters are expanded', async function (){ - const result = await tronWeb.ztron.createBurnParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress); - assert.ok(result && result.binding_signature && result.message_hash); - }) - - it('should trow if ak|nsk|ovk is not a string', async function (){ - const invalidAk = 1111; - const invalidNsk = 1111; - const invalidOvk = 1111; - - await assertThrow( - tronWeb.ztron.createBurnParamsWithoutAsk(invalidAk, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid ak provided' - ) - - await assertThrow( - tronWeb.ztron.createBurnParamsWithoutAsk(shieldedInfo.ak, invalidNsk, shieldedInfo.ovk, - shieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid nsk provided' - ) - - await assertThrow( - tronWeb.ztron.createBurnParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, invalidOvk, - shieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid ovk provided' - ) - }) - - it('should throw if shieldedSpends|shieldedReceives not an array', async function (){ - const invalidShieldedSpends = {}; - const invalidShieldedReceives = {}; - await assertThrow( - tronWeb.ztron.createBurnParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, shieldedInfo.ovk, - invalidShieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid shieldedSpends provided' - ) - - await assertThrow( - tronWeb.ztron.createBurnParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, invalidShieldedReceives, transParentToAddress, toAmount, shieldedAddress), - 'Invalid shieldedReceives provided' - ) - }) - - it('should throw if toAmount is not a string', async function (){ - const invalidToAmount = 10; - await assertThrow( - tronWeb.ztron.createBurnParamsWithoutAsk(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, burnShieldedReceives, transParentToAddress, invalidToAmount, shieldedAddress), - 'Invalid toAmount provided' - ) - }) - - it('should throw if transparentToAddress is not an address', async function (){ - const invalidTransparentToAddress = transParentToAddress.slice(0, 10); - await assertThrow( - tronWeb.ztron.createBurnParamsWithoutAsk(shieldedInfo.ask, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, burnShieldedReceives, invalidTransparentToAddress, toAmount, shieldedAddress), - 'Invalid transparentToAddress address provided' - ) - }) - - it('should throw if shieldedTRC20ContractAddress is not an address', async function (){ - const invalidShieldedTRC20ContractAddress = shieldedAddress.slice(0, 10); - await assertThrow( - tronWeb.ztron.createBurnParamsWithoutAsk(shieldedInfo.ak, shieldedInfo.nsk, shieldedInfo.ovk, - shieldedSpends, burnShieldedReceives, transParentToAddress, toAmount, invalidShieldedTRC20ContractAddress), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - }) - }) - - describe("#createSpendAuthSig Burn", async function (){ - let txHash; - let alpha; - before(async () => { - txHash = burnParamsResult.message_hash; - alpha = (await tronWeb.ztron.getRcm()).value; - }) - it('should get a value with txHash', async function (){ - const rcmInfo = await tronWeb.ztron.getRcm(); - const result = await tronWeb.ztron.createSpendAuthSig(shieldedInfo.ask, txHash, rcmInfo.value); - assert.ok(result && result.value); - spendAuthoritySignature = result.value; - }) - }) - - describe("#getTriggerInputForShieldedTRC20Contract Burn", function (){ - it('it should return transfer trigger_contract_input value', async function (){ - const shieldedTRC20Parameters = Object.assign({}, burnParamsResult); - const spendAuthoritySignatureArray = [{ - value: spendAuthoritySignature - }]; - const options = { - amount: toAmount, - transparent_to_address: transParentToAddress, - visible: true - } - const result = await tronWeb.ztron.getTriggerInputForShieldedTRC20Contract(shieldedTRC20Parameters, spendAuthoritySignatureArray, options); - assert.ok(result && result.value) - burnTriggerContractInput = result.value; - }) - }) - - }) - - describe("#isShieldedTRC20ContractNoteSpent", function (){ - let spendNote, pendingNote; - - before(async () => { - spendNote = shieldedSpends[0].note; - pendingNote = noteTxs[noteTxs.length - 1] - }) - - it('should return is_spent is true, The ak is an object', async function (){ - const params = { - note: spendNote, - ak: shieldedInfo.ak, - nk: shieldedInfo.nk, - position: shieldedSpends[0].pos, - shielded_TRC20_contract_address: shieldedAddress - } - const result = await tronWeb.ztron.isShieldedTRC20ContractNoteSpent(params); - assert.ok(result && result.is_spent); - }); - - it('should return is_spent is true, The parameters are expanded', async function (){ - const result = await tronWeb.ztron.isShieldedTRC20ContractNoteSpent(shieldedInfo.ak, shieldedInfo.nk, spendNote, shieldedSpends[0].pos, shieldedAddress); - assert.ok(result && result.is_spent); - }); - - it('should return is_spent is false', async function (){ - const params = { - note: pendingNote.note, - ak: shieldedInfo.ak, - nk: shieldedInfo.nk, - position: pendingNote.position, - shielded_TRC20_contract_address: shieldedAddress - } - const result = await tronWeb.ztron.isShieldedTRC20ContractNoteSpent(params); - assert.ok(result && !result.is_spent); - }) - - it('should throw if ak|nk is not a string', async function (){ - const invalidAk = 1111; - const invalidNk = 1111; - await assertThrow( - tronWeb.ztron.isShieldedTRC20ContractNoteSpent(invalidAk, shieldedInfo.nk, spendNote, shieldedSpends[0].pos, shieldedAddress), - 'Invalid ak provided' - ) - - await assertThrow( - tronWeb.ztron.isShieldedTRC20ContractNoteSpent(shieldedInfo.ak, invalidNk, spendNote, shieldedSpends[0].pos, shieldedAddress), - 'Invalid nk provided' - ) - }) - - it('should throw if note is not an object', async function (){ - const invalidNote = [] - await assertThrow( - tronWeb.ztron.isShieldedTRC20ContractNoteSpent(shieldedInfo.ak, shieldedInfo.nk, invalidNote, shieldedSpends[0].pos, shieldedAddress), - 'Invalid note provided' - ) - }) - - it('should throw if position is not an integer', async function (){ - const invalidPosition = "1" - await assertThrow( - tronWeb.ztron.isShieldedTRC20ContractNoteSpent(shieldedInfo.ak, shieldedInfo.nk, spendNote, invalidPosition, shieldedAddress), - 'Invalid position provided' - ) - }) - - it('should throw if shieldedTRC20ContractAddress is not an address', async function (){ - const invalidShieldedTRC20ContractAddress = shieldedAddress.slice(0, 10); - await assertThrow( - tronWeb.ztron.isShieldedTRC20ContractNoteSpent(shieldedInfo.ak, shieldedInfo.nk, spendNote, shieldedSpends[0].pos, invalidShieldedTRC20ContractAddress), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - }) - }) - - describe("#scanShieldedTRC20NotesByOvk", function (){ - const options = { - visible: true - } - it('should get noteTxs with startBlockIndex is object', async function (){ - await wait(10) - const params = { - "start_block_index": startBlockIndex, - "end_block_index": endBlockIndex, - "shielded_TRC20_contract_address": shieldedAddress, - "ovk": shieldedInfo.ovk, - } - const result = await tronWeb.ztron.scanShieldedTRC20NotesByOvk(params, options); - assert.ok(result && result.noteTxs && result.noteTxs.length > 0); - }) - - it('should get noteTxs with The parameters are expanded', async function (){ - const result = await tronWeb.ztron.scanShieldedTRC20NotesByOvk(startBlockIndex, endBlockIndex, shieldedInfo.ovk, shieldedAddress, options); - assert.ok(result && result.noteTxs && result.noteTxs.length > 0); - }) - - it('should throw if startBlockIndex not a positive-integer', async function (){ - const invalidStartBlockIndex = -10; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByOvk(invalidStartBlockIndex, endBlockIndex, shieldedInfo.ovk, shieldedAddress, options), - 'startBlockIndex must be a positive integer' - ) - const stringStartBlockIndex = '1001'; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByOvk(stringStartBlockIndex, endBlockIndex, shieldedInfo.ovk, shieldedAddress, options), - 'startBlockIndex must be a positive integer' - ) - }) - - it('should throw if endBlockIndex not a positive-integer', async function (){ - const invalidEndBlockIndex = -10; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByOvk(startBlockIndex, invalidEndBlockIndex, shieldedInfo.ovk, shieldedAddress, options), - 'endBlockIndex must be a positive integer' - ) - const stringEndBlockIndex = '1001'; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByOvk(startBlockIndex, stringEndBlockIndex, shieldedInfo.ovk, shieldedAddress, options), - 'endBlockIndex must be a positive integer' - ) - }) - - it('should throw if ovk is not a string', async function (){ - const invalidOvk = 1111; - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByOvk(startBlockIndex, endBlockIndex, invalidOvk, shieldedAddress, options), - 'Invalid ovk provided' - ) - }) - - it('should throw if shieldedTRC20ContractAddress is not an address', async function (){ - const invalidShieldedTRC20ContractAddress = shieldedAddress.slice(0, 10); - await assertThrow( - tronWeb.ztron.scanShieldedTRC20NotesByOvk(startBlockIndex, endBlockIndex, shieldedInfo.ovk, invalidShieldedTRC20ContractAddress, options), - 'Invalid shieldedTRC20ContractAddress address provided' - ) - }) - }) - - describe("redjubjub tool", function (){ - it('should all passed.', function (){ - const keys = tronWeb.ztron.generate_keys(); - assert.ok(keys.sk && keys.ask && keys.nsk && keys.ovk && keys.ak && keys.nk && keys.ivk && keys.d && keys.pk_d && keys.payment_address) - - const keysBySk = tronWeb.ztron.generate_keys_by_sk(keys.sk) - assert.ok(keysBySk.sk && keysBySk.ask && keysBySk.nsk && keysBySk.ovk && keysBySk.ak && keysBySk.nk - && keysBySk.ivk && keysBySk.d && keysBySk.pk_d && keysBySk.payment_address) - - const keysByskd = tronWeb.ztron.generate_keys_by_sk_d(keys.sk, keysBySk.d) - assert.ok(keysByskd.sk && keysByskd.ask && keysByskd.nsk && keysByskd.ovk && keysByskd.ak && keysByskd.nk - && keysByskd.ivk && keysByskd.d && keysByskd.pk_d && keysByskd.payment_address) - - const rk_by_ask = tronWeb.ztron.generate_rk_by_ask(keys.ask, '2608999c3a97d005a879ecdaa16fd29ae434fb67b177c5e875b0c829e6a1db05') - assert.ok(rk_by_ask) - - const spend_auth_sign = tronWeb.ztron.generate_spend_auth_sig(keys.ask, '2608999c3a97d005a879ecdaa16fd29ae434fb67b177c5e875b0c829e6a1db05', '3b78fee6e956f915ffe082284c5f18640edca9c57a5f227e5f7d7eb65ad61502') - assert.ok(spend_auth_sign) - - const verifySpendAuthSig = tronWeb.ztron.verify_spend_auth_sig(rk_by_ask, '3b78fee6e956f915ffe082284c5f18640edca9c57a5f227e5f7d7eb65ad61502', spend_auth_sign) - assert.ok(verifySpendAuthSig === true) - - const generate_pk_by_sk = tronWeb.ztron.generate_pk_by_sk(keys.ask); - assert.ok(generate_pk_by_sk) - - const generate_binding_sig = tronWeb.ztron.generate_binding_sig(keys.ask, '3b78fee6e956f915ffe082284c5f18640edca9c57a5f227e5f7d7eb65ad61502'); - assert.ok(generate_binding_sig) - - const verify_binding_sig = tronWeb.ztron.verify_binding_sig(generate_pk_by_sk, '3b78fee6e956f915ffe082284c5f18640edca9c57a5f227e5f7d7eb65ad61502', generate_binding_sig) - assert.ok(verify_binding_sig === true) - }) - }) -}) diff --git a/webpack.config.js b/webpack.config.js index 335796eb..a7dd83ba 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -42,9 +42,6 @@ const baseConfig = { path.resolve(__dirname, 'src') ], }, - node: { - fs: 'empty' - }, devtool: 'source-map', mode }; From 46b299a7494003d4632e65805b763ef1b1b41e2a Mon Sep 17 00:00:00 2001 From: "hamlin.li" Date: Fri, 18 Dec 2020 18:45:27 +0800 Subject: [PATCH 3/6] The createToken method supports 0 in its precision. --- package.json | 2 +- src/lib/transactionBuilder.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b60a045a..5ac305b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tronweb", - "version": "3.2.1", + "version": "3.2.2", "description": "JavaScript SDK that encapsulates the TRON HTTP API", "main": "dist/TronWeb.node.js", "scripts": { diff --git a/src/lib/transactionBuilder.js b/src/lib/transactionBuilder.js index be53f3c5..13566582 100644 --- a/src/lib/transactionBuilder.js +++ b/src/lib/transactionBuilder.js @@ -1035,8 +1035,8 @@ export default class TransactionBuilder { if (utils.isNotNullOrUndefined(voteScore) && (!utils.isInteger(voteScore) || voteScore <= 0)) return callback('voteScore must be a positive integer greater than 0'); - if (utils.isNotNullOrUndefined(precision) && (!utils.isInteger(precision) || precision <= 0 || precision > 6)) - return callback('precision must be a positive integer > 0 and <= 6'); + if (utils.isNotNullOrUndefined(precision) && (!utils.isInteger(precision) || precision < 0 || precision > 6)) + return callback('precision must be a positive integer >= 0 and <= 6'); const data = { owner_address: toHex(issuerAddress), From c3f9f5b47255ddcf1496e35df069f444dd0ddb3a Mon Sep 17 00:00:00 2001 From: "hamlin.li" Date: Wed, 23 Dec 2020 20:11:03 +0800 Subject: [PATCH 4/6] change the default feelimit value to 40 TRX --- src/index.js | 2 +- test/lib/transactionBuilder.test.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index a0a2fd32..9d1c482c 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,7 @@ import { ADDRESS_PREFIX } from 'utils/address'; const DEFAULT_VERSION = '3.5.0'; -const FEE_LIMIT = 20000000; +const FEE_LIMIT = 40000000; export default class TronWeb extends EventEmitter { static providers = providers; diff --git a/test/lib/transactionBuilder.test.js b/test/lib/transactionBuilder.test.js index 91e70a06..096bb69f 100644 --- a/test/lib/transactionBuilder.test.js +++ b/test/lib/transactionBuilder.test.js @@ -206,6 +206,18 @@ describe('TronWeb.transactionBuilder', function () { } }); + it(`should create a TestToken passing with precision is zero`, async function () { + const options = getTokenOptions(); + options.precision = 0 + for (let i = 0; i < 2; i++) { + if (i === 1) options.permissionId = 2; + const transaction = await tronWeb.transactionBuilder.createToken(options); + const parameter = txPars(transaction); + await assertEqualHex(parameter.value.abbr, options.abbreviation); + assert.equal(transaction.raw_data.contract[0].Permission_id || 0, options.permissionId || 0); + } + }); + it(`should create a TestToken without freezing anything in 3.6.0`, async function () { if (tronWeb.fullnodeSatisfies('^3.6.0')) { const options = getTokenOptions(); @@ -1159,7 +1171,7 @@ describe('TronWeb.transactionBuilder', function () { const tx = await tronWeb.transactionBuilder.createSmartContract(options) assert.equal(tx.raw_data.contract[0].parameter.value.new_contract.consume_user_resource_percent, 100); assert.equal(tx.raw_data.contract[0].parameter.value.new_contract.origin_energy_limit, 1e7); - assert.equal(tx.raw_data.fee_limit, 2e7); + assert.equal(tx.raw_data.fee_limit, 4e7); assert.equal(tx.raw_data.contract[0].Permission_id || 0, options.permissionId || 0); } }); From a2e52f45feb04ef24893356d802a644b15823a04 Mon Sep 17 00:00:00 2001 From: "hamlin.li" Date: Thu, 24 Dec 2020 12:05:56 +0800 Subject: [PATCH 5/6] add release notes --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 7d05ac0f..fa1fb477 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,10 @@ In order to contribute you can ## Recent History +__3.2.2__ +- Set feeLimit default value as 40 TRX +- The `createToken` method supports 0 in its precision + __3.1.0__ - Update `elliptic` to the latest version 6.5.3 - Update `ethers` to the latest version 5.0.8 From 928f3d911ced6f62a14054002a07158fbf1e9726 Mon Sep 17 00:00:00 2001 From: "hamlin.li" Date: Thu, 7 Jan 2021 12:40:03 +0800 Subject: [PATCH 6/6] Merge pull --- src/index.js | 2 +- src/lib/transactionBuilder.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index a0a2fd32..9d1c482c 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,7 @@ import { ADDRESS_PREFIX } from 'utils/address'; const DEFAULT_VERSION = '3.5.0'; -const FEE_LIMIT = 20000000; +const FEE_LIMIT = 40000000; export default class TronWeb extends EventEmitter { static providers = providers; diff --git a/src/lib/transactionBuilder.js b/src/lib/transactionBuilder.js index be53f3c5..13566582 100644 --- a/src/lib/transactionBuilder.js +++ b/src/lib/transactionBuilder.js @@ -1035,8 +1035,8 @@ export default class TransactionBuilder { if (utils.isNotNullOrUndefined(voteScore) && (!utils.isInteger(voteScore) || voteScore <= 0)) return callback('voteScore must be a positive integer greater than 0'); - if (utils.isNotNullOrUndefined(precision) && (!utils.isInteger(precision) || precision <= 0 || precision > 6)) - return callback('precision must be a positive integer > 0 and <= 6'); + if (utils.isNotNullOrUndefined(precision) && (!utils.isInteger(precision) || precision < 0 || precision > 6)) + return callback('precision must be a positive integer >= 0 and <= 6'); const data = { owner_address: toHex(issuerAddress),