UNPKG

caver-js

Version:

caver-js is a JavaScript API library that allows developers to interact with a Kaia node

1,028 lines (863 loc) 114 kB
/* Copyright 2018 The caver-js Authors This file is part of the caver-js library. The caver-js library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The caver-js library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the caver-js. If not, see <http://www.gnu.org/licenses/>. */ const { expect, assert } = require('../extendedChai') const testRPCURL = require('../testrpc') const Caver = require('../../index') let caver describe('FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO transaction', async () => { let accountUpdateObject let senderAddress let senderPrvKey let payerAddress let payerPrvKey let testAccount let publicKey let publicKey2 let publicKey3 let publicKey4 let privateKey2 let privateKey3 let privateKey4 let multisig const createTestAccount = () => { publicKey = caver.klay.accounts.privateKeyToPublicKey(caver.klay.accounts.create().privateKey) testAccount = caver.klay.accounts.wallet.add(caver.klay.accounts.create()) const txObject = { from: senderAddress, to: testAccount.address, value: caver.utils.toPeb(1, 'KLAY'), gas: 900000, } // account update transaction object accountUpdateObject = { type: 'FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO', from: testAccount.address, gas: 900000, feeRatio: 30, } return caver.klay.sendTransaction(txObject) } before(function(done) { this.timeout(200000) caver = new Caver(testRPCURL) senderPrvKey = process.env.privateKey && String(process.env.privateKey).indexOf('0x') === -1 ? `0x${process.env.privateKey}` : process.env.privateKey payerPrvKey = process.env.privateKey2 && String(process.env.privateKey2).indexOf('0x') === -1 ? `0x${process.env.privateKey2}` : process.env.privateKey2 caver.klay.accounts.wallet.add(senderPrvKey) caver.klay.accounts.wallet.add(payerPrvKey) const sender = caver.klay.accounts.privateKeyToAccount(senderPrvKey) senderAddress = sender.address const payer = caver.klay.accounts.privateKeyToAccount(payerPrvKey) payerAddress = payer.address // Make testAccount for update testing (This will be used for key update) privateKey2 = caver.klay.accounts.create().privateKey publicKey2 = caver.klay.accounts.privateKeyToPublicKey(privateKey2) privateKey3 = caver.klay.accounts.create().privateKey publicKey3 = caver.klay.accounts.privateKeyToPublicKey(privateKey3) privateKey4 = caver.klay.accounts.create().privateKey publicKey4 = caver.klay.accounts.privateKeyToPublicKey(privateKey4) multisig = { threshold: 2, keys: [{ weight: 1, publicKey: publicKey2 }, { weight: 1, publicKey: publicKey3 }, { weight: 1, publicKey: publicKey4 }], } createTestAccount().then(() => done()) }) // Error from missing it('CAVERJS-UNIT-TX-344 : If transaction object missing from, signTransaction should throw error', async () => { const tx = { publicKey, ...accountUpdateObject } delete tx.from await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('"from" is missing')) }).timeout(200000) it('CAVERJS-UNIT-TX-344 : If transaction object missing from, sendTransaction should throw error', async () => { const tx = { publicKey, ...accountUpdateObject } delete tx.from expect(() => caver.klay.sendTransaction(tx)).to.throw('The send transactions "from" field must be defined!') }).timeout(200000) // UnnecessaryTo it('CAVERJS-UNIT-TX-345 : If transaction object has to, signTransaction should throw error', async () => { const tx = { publicKey, to: senderAddress, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('"to" cannot be used with FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO transaction')) }).timeout(200000) it('CAVERJS-UNIT-TX-345 : If transaction object has to, sendTransaction should throw error', async () => { const tx = { publicKey, to: senderAddress, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( '"to" cannot be used with FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO transaction' ) }).timeout(200000) // UnnecessaryValue it('CAVERJS-UNIT-TX-346 : If transaction object has value, signTransaction should throw error', async () => { const tx = { publicKey, value: 1, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('"value" cannot be used with FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO transaction')) }).timeout(200000) it('CAVERJS-UNIT-TX-346 : If transaction object has value, sendTransaction should throw error', async () => { const tx = { publicKey, value: 1, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( '"value" cannot be used with FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO transaction' ) }).timeout(200000) // MissingGas it('CAVERJS-UNIT-TX-347 : If transaction object missing gas and gasLimit, signTransaction should throw error', async () => { const tx = { publicKey, ...accountUpdateObject } delete tx.gas await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('"gas" is missing')) }).timeout(200000) it('CAVERJS-UNIT-TX-347 : If transaction object missing gas and gasLimit, sendTransaction should throw error', async () => { const tx = { publicKey, ...accountUpdateObject } delete tx.gas expect(() => caver.klay.sendTransaction(tx)).to.throw('"gas" is missing') }).timeout(200000) // MissingKey it('CAVERJS-UNIT-TX-348 : If transaction object missing key information, signTransaction should throw error', async () => { const tx = { ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('Missing key information with FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO transaction')) }).timeout(200000) it('CAVERJS-UNIT-TX-348 : If transaction object missing key information, sendTransaction should throw error', async () => { const tx = { ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'Missing key information with FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO transaction' ) }).timeout(200000) // PublicKey it('CAVERJS-UNIT-TX-349 : If transaction object has only publicKey, update account with publicKey', async () => { const tx = { publicKey: publicKey3, ...accountUpdateObject } const ret = await caver.klay.accounts.signTransaction(tx, testAccount.privateKey) const feePayerTx = { senderRawTransaction: ret.rawTransaction, feePayer: payerAddress, } const receipt = await caver.klay.sendTransaction(feePayerTx) expect(receipt.from).to.equals(tx.from) expect(receipt.status).to.be.true const key = await caver.klay.getAccountKey(receipt.from) const xy = caver.utils.xyPointFromPublicKey(publicKey3) expect(key.keyType).to.equals(2) expect(key.key.x).to.equals(xy[0]) expect(key.key.y).to.equals(xy[1]) caver.klay.accounts.wallet.updatePrivateKey(privateKey3, testAccount.address) }).timeout(200000) // PublicKeyLength64 it('CAVERJS-UNIT-TX-351 : If compressed publicKey length is 64, signTransaction should throw error', async () => { const tx = { publicKey: caver.utils.randomHex(32), ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('Invalid public key')) }).timeout(200000) it('CAVERJS-UNIT-TX-351 : If compressed publicKey length is 64, sendTransaction should throw error', async () => { const tx = { publicKey: caver.utils.randomHex(32), ...accountUpdateObject } await caver.klay .sendTransaction(tx) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('Invalid public key')) }).timeout(200000) // PublicKeyLength126 it('CAVERJS-UNIT-TX-352 : If uncompressed publicKey length is 126, signTransaction should throw error', async () => { const tx = { publicKey: caver.utils.randomHex(63), ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('Invalid public key')) }).timeout(200000) it('CAVERJS-UNIT-TX-352 : If uncompressed publicKey length is 126, sendTransaction should throw error', async () => { const tx = { publicKey: caver.utils.randomHex(63), ...accountUpdateObject } await caver.klay .sendTransaction(tx) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('Invalid public key')) }).timeout(200000) // Update with multisig. it('CAVERJS-UNIT-TX-353 : If transaction object has multisig, update account with multisig', async () => { const tx = { multisig, ...accountUpdateObject } const ret = await caver.klay.accounts.signTransaction(tx, testAccount.privateKey) const receipt = await caver.klay.sendTransaction({ senderRawTransaction: ret.rawTransaction, feePayer: payerAddress, }) expect(receipt.from).to.equals(tx.from) expect(receipt.status).to.be.true const key = await caver.klay.getAccountKey(receipt.from) expect(key.keyType).to.equals(4) expect(key.key.threshold).to.equals(multisig.threshold) expect(key.key.keys.length).to.equals(multisig.keys.length) for (let i = 0; i < multisig.keys.length; i++) { const xy = caver.utils.xyPointFromPublicKey(multisig.keys[i].publicKey) expect(key.key.keys[i].weight).to.equals(multisig.keys[i].weight) expect(key.key.keys[i].key.x).to.equals(xy[0]) expect(key.key.keys[i].key.y).to.equals(xy[1]) } await createTestAccount() }).timeout(200000) // Update with multisig and publicKey. it('CAVERJS-UNIT-TX-354 : If transaction object has multisig and publicKey, signTransaction should throw error', async () => { const tx = { publicKey, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-354 : If transaction object has multisig and publicKey, sendTransaction should throw error', async () => { const tx = { publicKey, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleTransactionKey. it('CAVERJS-UNIT-TX-355 : If transaction object has roleTransactionKey, update account with roleTransactionKey', async () => { let tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey: publicKey2 }, roleFeePayerKey: { publicKey: publicKey3 }, ...accountUpdateObject, } delete tx.feeRatio tx.type = 'ACCOUNT_UPDATE' await caver.klay.sendTransaction(tx) caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address) tx = { roleTransactionKey: { publicKey: publicKey4 }, ...accountUpdateObject } const ret = await caver.klay.accounts.signTransaction(tx, testAccount.privateKey) const receipt = await caver.klay.sendTransaction({ senderRawTransaction: ret.rawTransaction, feePayer: payerAddress, }) expect(receipt.from).to.equals(tx.from) expect(receipt.status).to.be.true const key = await caver.klay.getAccountKey(receipt.from) const expectedTransactionKey = caver.utils.xyPointFromPublicKey(publicKey4) const expectedUpdateKey = caver.utils.xyPointFromPublicKey(publicKey2) const expectedFeePayerKey = caver.utils.xyPointFromPublicKey(publicKey3) expect(key.keyType).to.equals(5) expect(key.key.length).to.equals(3) expect(key.key[0].key.x).to.equals(expectedTransactionKey[0]) expect(key.key[0].key.y).to.equals(expectedTransactionKey[1]) expect(key.key[1].key.x).to.equals(expectedUpdateKey[0]) expect(key.key[1].key.y).to.equals(expectedUpdateKey[1]) expect(key.key[2].key.x).to.equals(expectedFeePayerKey[0]) expect(key.key[2].key.y).to.equals(expectedFeePayerKey[1]) await createTestAccount() }).timeout(200000) // Update with roleTransactionKey and publicKey. it('CAVERJS-UNIT-TX-356 : If transaction object has roleTransactionKey and publicKey, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, publicKey, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-356 : If transaction object has roleTransactionKey and publicKey, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, publicKey, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleTransactionKey and multisig. it('CAVERJS-UNIT-TX-357 : If transaction object has roleTransactionKey and multisig, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-357 : If transaction object has roleTransactionKey and multisig, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleTransactionKey, publicKey and multisig. it('CAVERJS-UNIT-TX-358 : If transaction object has roleTransactionKey, publicKey and multisig, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, publicKey, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-358 : If transaction object has roleTransactionKey, publicKey and multisig, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, publicKey, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleAccountUpdateKey. it('CAVERJS-UNIT-TX-359 : If transaction object has roleAccountUpdateKey, update account with roleAccountUpdateKey', async () => { let tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey: publicKey2 }, roleFeePayerKey: { publicKey: publicKey3 }, ...accountUpdateObject, } delete tx.feeRatio tx.type = 'ACCOUNT_UPDATE' await caver.klay.sendTransaction(tx) caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address) tx = { roleAccountUpdateKey: { publicKey: publicKey4 }, ...accountUpdateObject } const ret = await caver.klay.accounts.signTransaction(tx, testAccount.privateKey) const receipt = await caver.klay.sendTransaction({ senderRawTransaction: ret.rawTransaction, feePayer: payerAddress, }) expect(receipt.from).to.equals(tx.from) expect(receipt.status).to.be.true const key = await caver.klay.getAccountKey(receipt.from) const expectedTransactionKey = caver.utils.xyPointFromPublicKey(publicKey) const expectedUpdateKey = caver.utils.xyPointFromPublicKey(publicKey4) const expectedFeePayerKey = caver.utils.xyPointFromPublicKey(publicKey3) expect(key.keyType).to.equals(5) expect(key.key.length).to.equals(3) expect(key.key[0].key.x).to.equals(expectedTransactionKey[0]) expect(key.key[0].key.y).to.equals(expectedTransactionKey[1]) expect(key.key[1].key.x).to.equals(expectedUpdateKey[0]) expect(key.key[1].key.y).to.equals(expectedUpdateKey[1]) expect(key.key[2].key.x).to.equals(expectedFeePayerKey[0]) expect(key.key[2].key.y).to.equals(expectedFeePayerKey[1]) await createTestAccount() }).timeout(200000) // Update with roleAccountUpdateKey and roleTransactionKey. it('CAVERJS-UNIT-TX-360 : If transaction object has roleAccountUpdateKey and roleTransactionKey, update account with roleAccountUpdateKey and roleTransactionKey', async () => { let tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey: publicKey2 }, roleFeePayerKey: { publicKey: publicKey3 }, ...accountUpdateObject, } delete tx.feeRatio tx.type = 'ACCOUNT_UPDATE' await caver.klay.sendTransaction(tx) caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address) tx = { roleTransactionKey: { publicKey: publicKey4 }, roleAccountUpdateKey: { publicKey }, ...accountUpdateObject } const ret = await caver.klay.accounts.signTransaction(tx, testAccount.privateKey) const receipt = await caver.klay.sendTransaction({ senderRawTransaction: ret.rawTransaction, feePayer: payerAddress, }) expect(receipt.from).to.equals(tx.from) expect(receipt.status).to.be.true const key = await caver.klay.getAccountKey(receipt.from) const expectedTransactionKey = caver.utils.xyPointFromPublicKey(publicKey4) const expectedUpdateKey = caver.utils.xyPointFromPublicKey(publicKey) const expectedFeePayerKey = caver.utils.xyPointFromPublicKey(publicKey3) expect(key.keyType).to.equals(5) expect(key.key.length).to.equals(3) expect(key.key[0].key.x).to.equals(expectedTransactionKey[0]) expect(key.key[0].key.y).to.equals(expectedTransactionKey[1]) expect(key.key[1].key.x).to.equals(expectedUpdateKey[0]) expect(key.key[1].key.y).to.equals(expectedUpdateKey[1]) expect(key.key[2].key.x).to.equals(expectedFeePayerKey[0]) expect(key.key[2].key.y).to.equals(expectedFeePayerKey[1]) await createTestAccount() }).timeout(200000) // Update with roleAccountUpdateKey and publicKey. it('CAVERJS-UNIT-TX-361 : If transaction object has roleAccountUpdateKey and publicKey, signTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, publicKey, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-361 : If transaction object has roleAccountUpdateKey and publicKey, sendTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, publicKey, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleAccountUpdateKey and multisig. it('CAVERJS-UNIT-TX-362 : If transaction object has roleAccountUpdateKey and multisig, signTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-362 : If transaction object has roleAccountUpdateKey and multisig, sendTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleAccountUpdateKey, publicKey and multisig. it('CAVERJS-UNIT-TX-363 : If transaction object has roleAccountUpdateKey, publicKey and multisig, signTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, publicKey, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-363 : If transaction object has roleAccountUpdateKey, publicKey and multisig, sendTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, publicKey, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleAccountUpdateKey, roleTransactionKey and publicKey. it('CAVERJS-UNIT-TX-364 : If transaction object has roleAccountUpdateKey, roleTransactionKey and publicKey, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, publicKey, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-364 : If transaction object has roleAccountUpdateKey, roleTransactionKey and publicKey, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, publicKey, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleAccountUpdateKey, roleTransactionKey and multisig. it('CAVERJS-UNIT-TX-365 : If transaction object has roleAccountUpdateKey, roleTransactionKey and multisig, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-365 : If transaction object has roleAccountUpdateKey, roleTransactionKey and multisig, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleAccountUpdateKey, roleTransactionKey, publicKey and multisig. it('CAVERJS-UNIT-TX-366 : If transaction object has roleAccountUpdateKey, roleTransactionKey, publicKey and multisig, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, publicKey, multisig, ...accountUpdateObject, } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-366 : If transaction object has roleAccountUpdateKey, roleTransactionKey, publicKey and multisig, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, publicKey, multisig, ...accountUpdateObject, } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey. it('CAVERJS-UNIT-TX-367 : If transaction object has roleFeePayerKey, update account with roleFeePayerKey', async () => { let tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey: publicKey2 }, roleFeePayerKey: { publicKey: publicKey3 }, ...accountUpdateObject, } delete tx.feeRatio tx.type = 'ACCOUNT_UPDATE' await caver.klay.sendTransaction(tx) caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address) tx = { roleFeePayerKey: { publicKey: publicKey4 }, ...accountUpdateObject } const ret = await caver.klay.accounts.signTransaction(tx, testAccount.privateKey) const receipt = await caver.klay.sendTransaction({ senderRawTransaction: ret.rawTransaction, feePayer: payerAddress, }) expect(receipt.from).to.equals(tx.from) expect(receipt.status).to.be.true const key = await caver.klay.getAccountKey(receipt.from) const expectedTransactionKey = caver.utils.xyPointFromPublicKey(publicKey) const expectedUpdateKey = caver.utils.xyPointFromPublicKey(publicKey2) const expectedFeePayerKey = caver.utils.xyPointFromPublicKey(publicKey4) expect(key.keyType).to.equals(5) expect(key.key.length).to.equals(3) expect(key.key[0].key.x).to.equals(expectedTransactionKey[0]) expect(key.key[0].key.y).to.equals(expectedTransactionKey[1]) expect(key.key[1].key.x).to.equals(expectedUpdateKey[0]) expect(key.key[1].key.y).to.equals(expectedUpdateKey[1]) expect(key.key[2].key.x).to.equals(expectedFeePayerKey[0]) expect(key.key[2].key.y).to.equals(expectedFeePayerKey[1]) await createTestAccount() }).timeout(200000) // Update with roleFeePayerKey and roleTransactionKey. it('CAVERJS-UNIT-TX-368 : If transaction object has roleFeePayerKey and roleTransactionKey, update account with roleFeePayerKey and roleTransactionKey', async () => { let tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey: publicKey2 }, roleFeePayerKey: { publicKey: publicKey3 }, ...accountUpdateObject, } delete tx.feeRatio tx.type = 'ACCOUNT_UPDATE' await caver.klay.sendTransaction(tx) caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address) tx = { roleTransactionKey: { publicKey: publicKey3 }, roleFeePayerKey: { publicKey: publicKey4 }, ...accountUpdateObject, } const ret = await caver.klay.accounts.signTransaction(tx, testAccount.privateKey) const receipt = await caver.klay.sendTransaction({ senderRawTransaction: ret.rawTransaction, feePayer: payerAddress, }) expect(receipt.from).to.equals(tx.from) expect(receipt.status).to.be.true const key = await caver.klay.getAccountKey(receipt.from) const expectedTransactionKey = caver.utils.xyPointFromPublicKey(publicKey3) const expectedUpdateKey = caver.utils.xyPointFromPublicKey(publicKey2) const expectedFeePayerKey = caver.utils.xyPointFromPublicKey(publicKey4) expect(key.keyType).to.equals(5) expect(key.key.length).to.equals(3) expect(key.key[0].key.x).to.equals(expectedTransactionKey[0]) expect(key.key[0].key.y).to.equals(expectedTransactionKey[1]) expect(key.key[1].key.x).to.equals(expectedUpdateKey[0]) expect(key.key[1].key.y).to.equals(expectedUpdateKey[1]) expect(key.key[2].key.x).to.equals(expectedFeePayerKey[0]) expect(key.key[2].key.y).to.equals(expectedFeePayerKey[1]) await createTestAccount() }).timeout(200000) // Update with roleFeePayerKey and roleAccountUpdateKey. it('CAVERJS-UNIT-TX-369 : If transaction object has roleFeePayerKey and roleAccountUpdateKey, update account with roleFeePayerKey and roleAccountUpdateKey', async () => { let tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey: publicKey2 }, roleFeePayerKey: { publicKey: publicKey3 }, ...accountUpdateObject, } delete tx.feeRatio tx.type = 'ACCOUNT_UPDATE' await caver.klay.sendTransaction(tx) caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address) tx = { roleAccountUpdateKey: { publicKey: publicKey3 }, roleFeePayerKey: { publicKey: publicKey4 }, ...accountUpdateObject, } const ret = await caver.klay.accounts.signTransaction(tx, testAccount.privateKey) const receipt = await caver.klay.sendTransaction({ senderRawTransaction: ret.rawTransaction, feePayer: payerAddress, }) expect(receipt.from).to.equals(tx.from) expect(receipt.status).to.be.true const key = await caver.klay.getAccountKey(receipt.from) const expectedTransactionKey = caver.utils.xyPointFromPublicKey(publicKey) const expectedUpdateKey = caver.utils.xyPointFromPublicKey(publicKey3) const expectedFeePayerKey = caver.utils.xyPointFromPublicKey(publicKey4) expect(key.keyType).to.equals(5) expect(key.key.length).to.equals(3) expect(key.key[0].key.x).to.equals(expectedTransactionKey[0]) expect(key.key[0].key.y).to.equals(expectedTransactionKey[1]) expect(key.key[1].key.x).to.equals(expectedUpdateKey[0]) expect(key.key[1].key.y).to.equals(expectedUpdateKey[1]) expect(key.key[2].key.x).to.equals(expectedFeePayerKey[0]) expect(key.key[2].key.y).to.equals(expectedFeePayerKey[1]) await createTestAccount() }).timeout(200000) // Update with roleTransactionKey, roleAccountUpdateKey and roleFeePayerKey. it('CAVERJS-UNIT-TX-370 : If transaction object has roleTransactionKey, roleAccountUpdateKey and roleFeePayerKey, update account with roleTransactionKey, roleAccountUpdateKey and roleFeePayerKey', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey: publicKey2 }, roleFeePayerKey: { publicKey: publicKey3 }, ...accountUpdateObject, } const ret = await caver.klay.accounts.signTransaction(tx, testAccount.privateKey) const receipt = await caver.klay.sendTransaction({ senderRawTransaction: ret.rawTransaction, feePayer: payerAddress, }) expect(receipt.from).to.equals(tx.from) expect(receipt.status).to.be.true const key = await caver.klay.getAccountKey(receipt.from) const expectedTransactionKey = caver.utils.xyPointFromPublicKey(publicKey) const expectedUpdateKey = caver.utils.xyPointFromPublicKey(publicKey2) const expectedFeePayerKey = caver.utils.xyPointFromPublicKey(publicKey3) expect(key.keyType).to.equals(5) expect(key.key.length).to.equals(3) expect(key.key[0].key.x).to.equals(expectedTransactionKey[0]) expect(key.key[0].key.y).to.equals(expectedTransactionKey[1]) expect(key.key[1].key.x).to.equals(expectedUpdateKey[0]) expect(key.key[1].key.y).to.equals(expectedUpdateKey[1]) expect(key.key[2].key.x).to.equals(expectedFeePayerKey[0]) expect(key.key[2].key.y).to.equals(expectedFeePayerKey[1]) await createTestAccount() }).timeout(200000) // Update with roleFeePayerKey and publicKey. it('CAVERJS-UNIT-TX-371 : If transaction object has roleFeePayerKey and publicKey, signTransaction should throw error', async () => { const tx = { roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-371 : If transaction object has roleFeePayerKey and publicKey, sendTransaction should throw error', async () => { const tx = { roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey and multisig. it('CAVERJS-UNIT-TX-372 : If transaction object has roleFeePayerKey and multisig, signTransaction should throw error', async () => { const tx = { roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-372 : If transaction object has roleFeePayerKey and multisig, sendTransaction should throw error', async () => { const tx = { roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, publicKey and multisig. it('CAVERJS-UNIT-TX-373 : If transaction object has roleFeePayerKey, publicKey and multisig, signTransaction should throw error', async () => { const tx = { roleFeePayerKey: { publicKey }, publicKey, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-373 : If transaction object has roleFeePayerKey, publicKey and multisig, sendTransaction should throw error', async () => { const tx = { roleFeePayerKey: { publicKey }, publicKey, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, roleTransactionKey and publicKey. it('CAVERJS-UNIT-TX-374 : If transaction object has roleFeePayerKey, roleTransactionKey and publicKey, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-374 : If transaction object has roleFeePayerKey, roleTransactionKey and publicKey, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, roleTransactionKey and multisig. it('CAVERJS-UNIT-TX-375 : If transaction object has roleFeePayerKey, roleTransactionKey and multisig, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-375 : If transaction object has roleFeePayerKey, roleTransactionKey and multisig, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, roleTransactionKey, publicKey and multisig. it('CAVERJS-UNIT-TX-376 : If transaction object has roleFeePayerKey, roleTransactionKey, publicKey and multisig, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, multisig, ...accountUpdateObject, } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-376 : If transaction object has roleFeePayerKey, roleTransactionKey, publicKey and multisig, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, multisig, ...accountUpdateObject, } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, roleAccountUpdateKey and publicKey. it('CAVERJS-UNIT-TX-377 : If transaction object has roleFeePayerKey, roleAccountUpdateKey and publicKey, signTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-377 : If transaction object has roleFeePayerKey, roleAccountUpdateKey and publicKey, sendTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, roleAccountUpdateKey and multisig. it('CAVERJS-UNIT-TX-378 : If transaction object has roleFeePayerKey, roleAccountUpdateKey and multisig, signTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-378 : If transaction object has roleFeePayerKey, roleAccountUpdateKey and multisig, sendTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, roleAccountUpdateKey, publicKey and multisig. it('CAVERJS-UNIT-TX-379 : If transaction object has roleFeePayerKey, roleAccountUpdateKey, publicKey and multisig, signTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, multisig, ...accountUpdateObject, } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-379 : If transaction object has roleFeePayerKey, roleAccountUpdateKey, publicKey and multisig, sendTransaction should throw error', async () => { const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, multisig, ...accountUpdateObject, } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and publicKey. it('CAVERJS-UNIT-TX-380 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and publicKey, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject, } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-380 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and publicKey, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject, } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and multisig. it('CAVERJS-UNIT-TX-381 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and multisig, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject, } await caver.klay.accounts .signTransaction(tx, testAccount.privateKey) .then(() => assert(false)) .catch(err => expect(err.message).to.equals('The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.') ) }).timeout(200000) it('CAVERJS-UNIT-TX-381 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and multisig, sendTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject, } expect(() => caver.klay.sendTransaction(tx)).to.throw( 'The key parameter to be used for FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO is duplicated.' ) }).timeout(200000) // Update with roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey, publicKey and multisig. it('CAVERJS-UNIT-TX-382 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey, publicKey and multisig, signTransaction should throw error', async () => { const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: {