caver-js
Version:
caver-js is a JavaScript API library that allows developers to interact with a Klaytn node
1,118 lines (902 loc) • 97.5 kB
JavaScript
/*
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
let senderPrvKey
let senderAddress
let testAccount
describe('ACCOUNT_UPDATE transaction', async () => {
let accountUpdateObject
let publicKey
let publicKey2
let publicKey3
let publicKey4
let privateKey2
let privateKey3
let privateKey4
let multisig
const createTestAccount = () => {
testAccount = caver.klay.accounts.wallet.add(caver.klay.accounts.create())
publicKey = caver.klay.accounts.privateKeyToPublicKey(caver.klay.accounts.create().privateKey)
const txObject = {
from: senderAddress,
to: testAccount.address,
value: caver.utils.toPeb(1, 'KLAY'),
gas: 900000,
}
// account update transaction object
accountUpdateObject = {
type: 'ACCOUNT_UPDATE',
from: testAccount.address,
gas: 900000,
}
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
caver.klay.accounts.wallet.add(senderPrvKey)
const sender = caver.klay.accounts.privateKeyToAccount(senderPrvKey)
senderAddress = sender.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-187 : If transaction object missing from, signTransaction should throw error', async () => {
const tx = { publicKey, ...accountUpdateObject }
delete tx.from
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-187 : If transaction object missing from, sendTransaction should throw error', async () => {
const tx = { publicKey, ...accountUpdateObject }
delete tx.from
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// UnnecessaryTo
it('CAVERJS-UNIT-TX-188 : If transaction object has to, signTransaction should throw error', async () => {
const tx = { publicKey, to: senderAddress, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-188 : If transaction object has to, sendTransaction should throw error', async () => {
const tx = { publicKey, to: senderAddress, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// UnnecessaryValue
it('CAVERJS-UNIT-TX-189 : If transaction object has value, signTransaction should throw error', async () => {
const tx = { publicKey, value: 1, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-189 : If transaction object has value, sendTransaction should throw error', async () => {
const tx = { publicKey, value: 1, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// MissingGas
it('CAVERJS-UNIT-TX-190 : If transaction object missing gas and gasLimit, signTransaction should throw error', async () => {
const tx = { publicKey, ...accountUpdateObject }
delete tx.gas
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-190 : If transaction object missing gas and gasLimit, sendTransaction should throw error', async () => {
const tx = { publicKey, ...accountUpdateObject }
delete tx.gas
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// MissingKey
it('CAVERJS-UNIT-TX-191 : 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 ACCOUNT_UPDATE transaction')
})
}).timeout(200000)
it('CAVERJS-UNIT-TX-191 : If transaction object missing key information, sendTransaction should throw error', async () => {
const tx = { ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throws('Missing key information with ACCOUNT_UPDATE transaction')
}).timeout(200000)
// PublicKey
it('CAVERJS-UNIT-TX-192 : If transaction object has only publicKey, update account with publicKey', async () => {
const tx = { publicKey: publicKey3, ...accountUpdateObject }
const receipt = await caver.klay.sendTransaction(tx)
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-194 : If compressed publicKey length is 64, signTransaction should throw error', async () => {
const tx = { publicKey: caver.utils.randomHex(32), ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-194 : If compressed publicKey length is 64, sendTransaction should throw error', async () => {
const tx = { publicKey: caver.utils.randomHex(32), ...accountUpdateObject }
let result
await caver.klay
.sendTransaction(tx)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
// PublicKeyLength126
it('CAVERJS-UNIT-TX-195 : If uncompressed publicKey length is 126, signTransaction should throw error', async () => {
const tx = { publicKey: caver.utils.randomHex(63), ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-195 : If uncompressed publicKey length is 126, sendTransaction should throw error', async () => {
const tx = { publicKey: caver.utils.randomHex(63), ...accountUpdateObject }
let result
await caver.klay
.sendTransaction(tx)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
// Update with multisig.
it('CAVERJS-UNIT-TX-196 : If transaction object has multisig, update account with multisig', async () => {
const tx = { multisig, ...accountUpdateObject }
const receipt = await caver.klay.sendTransaction(tx)
expect(receipt.from).to.equals(tx.from)
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-197 : If transaction object has multisig and publicKey, signTransaction should throw error', async () => {
const tx = { publicKey, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-197 : If transaction object has multisig and publicKey, sendTransaction should throw error', async () => {
const tx = { publicKey, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleTransactionKey.
it('CAVERJS-UNIT-TX-198 : If transaction object has roleTransactionKey, update account with roleTransactionKey', async () => {
let tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey: publicKey2 },
roleFeePayerKey: { publicKey: publicKey3 },
...accountUpdateObject,
}
await caver.klay.sendTransaction(tx)
caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address)
tx = { roleTransactionKey: { publicKey: publicKey4 }, ...accountUpdateObject }
const receipt = await caver.klay.sendTransaction(tx)
expect(receipt.from).to.equals(tx.from)
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-199 : If transaction object has roleTransactionKey and publicKey, signTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, publicKey, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-199 : If transaction object has roleTransactionKey and publicKey, sendTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, publicKey, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleTransactionKey and multisig.
it('CAVERJS-UNIT-TX-200 : If transaction object has roleTransactionKey and multisig, signTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-200 : If transaction object has roleTransactionKey and multisig, sendTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleTransactionKey, publicKey and multisig.
it('CAVERJS-UNIT-TX-201 : If transaction object has roleTransactionKey, publicKey and multisig, signTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, publicKey, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-201 : If transaction object has roleTransactionKey, publicKey and multisig, sendTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, publicKey, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleAccountUpdateKey.
it('CAVERJS-UNIT-TX-202 : If transaction object has roleAccountUpdateKey, update account with roleAccountUpdateKey', async () => {
let tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey: publicKey2 },
roleFeePayerKey: { publicKey: publicKey3 },
...accountUpdateObject,
}
await caver.klay.sendTransaction(tx)
caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address)
tx = { roleAccountUpdateKey: { publicKey: publicKey4 }, ...accountUpdateObject }
const receipt = await caver.klay.sendTransaction(tx)
expect(receipt.from).to.equals(tx.from)
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-203 : 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,
}
await caver.klay.sendTransaction(tx)
caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address)
tx = { roleTransactionKey: { publicKey: publicKey4 }, roleAccountUpdateKey: { publicKey }, ...accountUpdateObject }
const receipt = await caver.klay.sendTransaction(tx)
expect(receipt.from).to.equals(tx.from)
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-204 : If transaction object has roleAccountUpdateKey and publicKey, signTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, publicKey, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-204 : If transaction object has roleAccountUpdateKey and publicKey, sendTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, publicKey, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleAccountUpdateKey and multisig.
it('CAVERJS-UNIT-TX-205 : If transaction object has roleAccountUpdateKey and multisig, signTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-205 : If transaction object has roleAccountUpdateKey and multisig, sendTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleAccountUpdateKey, publicKey and multisig.
it('CAVERJS-UNIT-TX-206 : If transaction object has roleAccountUpdateKey, publicKey and multisig, signTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, publicKey, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-206 : If transaction object has roleAccountUpdateKey, publicKey and multisig, sendTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, publicKey, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleAccountUpdateKey, roleTransactionKey and publicKey.
it('CAVERJS-UNIT-TX-207 : If transaction object has roleAccountUpdateKey, roleTransactionKey and publicKey, signTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, publicKey, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-207 : If transaction object has roleAccountUpdateKey, roleTransactionKey and publicKey, sendTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, publicKey, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleAccountUpdateKey, roleTransactionKey and multisig.
it('CAVERJS-UNIT-TX-208 : If transaction object has roleAccountUpdateKey, roleTransactionKey and multisig, signTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-208 : If transaction object has roleAccountUpdateKey, roleTransactionKey and multisig, sendTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, roleAccountUpdateKey: { publicKey }, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleAccountUpdateKey, roleTransactionKey, publicKey and multisig.
it('CAVERJS-UNIT-TX-209 : If transaction object has roleAccountUpdateKey, roleTransactionKey, publicKey and multisig, signTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey },
publicKey,
multisig,
...accountUpdateObject,
}
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-209 : If transaction object has roleAccountUpdateKey, roleTransactionKey, publicKey and multisig, sendTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey },
publicKey,
multisig,
...accountUpdateObject,
}
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey.
it('CAVERJS-UNIT-TX-210 : If transaction object has roleFeePayerKey, update account with roleFeePayerKey', async () => {
let tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey: publicKey2 },
roleFeePayerKey: { publicKey: publicKey3 },
...accountUpdateObject,
}
await caver.klay.sendTransaction(tx)
caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address)
tx = { roleFeePayerKey: { publicKey: publicKey4 }, ...accountUpdateObject }
const receipt = await caver.klay.sendTransaction(tx)
expect(receipt.from).to.equals(tx.from)
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-211 : 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,
}
await caver.klay.sendTransaction(tx)
caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address)
tx = {
roleTransactionKey: { publicKey: publicKey3 },
roleFeePayerKey: { publicKey: publicKey4 },
...accountUpdateObject,
}
const receipt = await caver.klay.sendTransaction(tx)
expect(receipt.from).to.equals(tx.from)
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-212 : 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,
}
await caver.klay.sendTransaction(tx)
caver.klay.accounts.wallet.updatePrivateKey(privateKey2, testAccount.address)
tx = {
roleAccountUpdateKey: { publicKey: publicKey3 },
roleFeePayerKey: { publicKey: publicKey4 },
...accountUpdateObject,
}
const receipt = await caver.klay.sendTransaction(tx)
expect(receipt.from).to.equals(tx.from)
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-213 : 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 receipt = await caver.klay.sendTransaction(tx)
expect(receipt.from).to.equals(tx.from)
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-214 : If transaction object has roleFeePayerKey and publicKey, signTransaction should throw error', async () => {
const tx = { roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-214 : If transaction object has roleFeePayerKey and publicKey, sendTransaction should throw error', async () => {
const tx = { roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey and multisig.
it('CAVERJS-UNIT-TX-215 : If transaction object has roleFeePayerKey and multisig, signTransaction should throw error', async () => {
const tx = { roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-215 : If transaction object has roleFeePayerKey and multisig, sendTransaction should throw error', async () => {
const tx = { roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, publicKey and multisig.
it('CAVERJS-UNIT-TX-216 : If transaction object has roleFeePayerKey, publicKey and multisig, signTransaction should throw error', async () => {
const tx = { roleFeePayerKey: { publicKey }, publicKey, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-216 : If transaction object has roleFeePayerKey, publicKey and multisig, sendTransaction should throw error', async () => {
const tx = { roleFeePayerKey: { publicKey }, publicKey, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, roleTransactionKey and publicKey.
it('CAVERJS-UNIT-TX-217 : If transaction object has roleFeePayerKey, roleTransactionKey and publicKey, signTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-217 : If transaction object has roleFeePayerKey, roleTransactionKey and publicKey, sendTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, roleTransactionKey and multisig.
it('CAVERJS-UNIT-TX-218 : If transaction object has roleFeePayerKey, roleTransactionKey and multisig, signTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-218 : If transaction object has roleFeePayerKey, roleTransactionKey and multisig, sendTransaction should throw error', async () => {
const tx = { roleTransactionKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, roleTransactionKey, publicKey and multisig.
it('CAVERJS-UNIT-TX-219 : If transaction object has roleFeePayerKey, roleTransactionKey, publicKey and multisig, signTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleFeePayerKey: { publicKey },
publicKey,
multisig,
...accountUpdateObject,
}
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-219 : If transaction object has roleFeePayerKey, roleTransactionKey, publicKey and multisig, sendTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleFeePayerKey: { publicKey },
publicKey,
multisig,
...accountUpdateObject,
}
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, roleAccountUpdateKey and publicKey.
it('CAVERJS-UNIT-TX-220 : If transaction object has roleFeePayerKey, roleAccountUpdateKey and publicKey, signTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-220 : If transaction object has roleFeePayerKey, roleAccountUpdateKey and publicKey, sendTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, publicKey, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, roleAccountUpdateKey and multisig.
it('CAVERJS-UNIT-TX-221 : If transaction object has roleFeePayerKey, roleAccountUpdateKey and multisig, signTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-221 : If transaction object has roleFeePayerKey, roleAccountUpdateKey and multisig, sendTransaction should throw error', async () => {
const tx = { roleAccountUpdateKey: { publicKey }, roleFeePayerKey: { publicKey }, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, roleAccountUpdateKey, publicKey and multisig.
it('CAVERJS-UNIT-TX-222 : If transaction object has roleFeePayerKey, roleAccountUpdateKey, publicKey and multisig, signTransaction should throw error', async () => {
const tx = {
roleAccountUpdateKey: { publicKey },
roleFeePayerKey: { publicKey },
publicKey,
multisig,
...accountUpdateObject,
}
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-222 : If transaction object has roleFeePayerKey, roleAccountUpdateKey, publicKey and multisig, sendTransaction should throw error', async () => {
const tx = {
roleAccountUpdateKey: { publicKey },
roleFeePayerKey: { publicKey },
publicKey,
multisig,
...accountUpdateObject,
}
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and publicKey.
it('CAVERJS-UNIT-TX-223 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and publicKey, signTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey },
roleFeePayerKey: { publicKey },
publicKey,
...accountUpdateObject,
}
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-223 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and publicKey, sendTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey },
roleFeePayerKey: { publicKey },
publicKey,
...accountUpdateObject,
}
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and multisig.
it('CAVERJS-UNIT-TX-224 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and multisig, signTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey },
roleFeePayerKey: { publicKey },
multisig,
...accountUpdateObject,
}
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-224 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey and multisig, sendTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey },
roleFeePayerKey: { publicKey },
multisig,
...accountUpdateObject,
}
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey, publicKey and multisig.
it('CAVERJS-UNIT-TX-225 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey, publicKey and multisig, signTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey },
roleFeePayerKey: { publicKey },
publicKey,
multisig,
...accountUpdateObject,
}
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-225 : If transaction object has roleFeePayerKey, roleTransactionKey, roleAccountUpdateKey, publicKey and multisig, sendTransaction should throw error', async () => {
const tx = {
roleTransactionKey: { publicKey },
roleAccountUpdateKey: { publicKey },
roleFeePayerKey: { publicKey },
publicKey,
multisig,
...accountUpdateObject,
}
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with failKey.
it('CAVERJS-UNIT-TX-226 : If transaction object has failKey, update account with failKey', async () => {
const tx = { failKey: true, ...accountUpdateObject }
const receipt = await caver.klay.sendTransaction(tx)
expect(receipt.from).to.equals(tx.from)
const key = await caver.klay.getAccountKey(receipt.from)
expect(key.keyType).to.equals(3)
await createTestAccount()
}).timeout(200000)
// Update with failKey and publicKey.
it('CAVERJS-UNIT-TX-227 : If transaction object has failKey and publicKey, signTransaction should throw error', async () => {
const tx = { failKey: true, publicKey, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-227 : If transaction object has failKey and publicKey, sendTransaction should throw error', async () => {
const tx = { failKey: true, publicKey, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with failKey and multisig.
it('CAVERJS-UNIT-TX-228 : If transaction object has failKey and multisig, signTransaction should throw error', async () => {
const tx = { failKey: true, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-228 : If transaction object has failKey and multisig, sendTransaction should throw error', async () => {
const tx = { failKey: true, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with failKey, publicKey and multisig.
it('CAVERJS-UNIT-TX-229 : If transaction object has failKey, publicKey and multisig, signTransaction should throw error', async () => {
const tx = { failKey: true, publicKey, multisig, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-229 : If transaction object has failKey, publicKey and multisig, sendTransaction should throw error', async () => {
const tx = { failKey: true, publicKey, multisig, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with failKey and roleTransactionKey.
it('CAVERJS-UNIT-TX-230 : If transaction object has failKey and roleTransactionKey, signTransaction should throw error', async () => {
const tx = { failKey: true, roleTransactionKey: { publicKey }, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-230 : If transaction object has failKey and roleTransactionKey, sendTransaction should throw error', async () => {
const tx = { failKey: true, roleTransactionKey: { publicKey }, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with failKey, roleTransactionKey and publicKey.
it('CAVERJS-UNIT-TX-231 : If transaction object has failKey, roleTransactionKey and publicKey, signTransaction should throw error', async () => {
const tx = { failKey: true, roleTransactionKey: { publicKey }, publicKey, ...accountUpdateObject }
let result
await caver.klay.accounts
.signTransaction(tx, testAccount.privateKey)
.then(() => (result = false))
.catch(() => (result = true))
expect(result).to.be.true
}).timeout(200000)
it('CAVERJS-UNIT-TX-231 : If transaction object has failKey, roleTransactionKey and publicKey, sendTransaction should throw error', async () => {
const tx = { failKey: true, roleTransactionKey: { publicKey }, publicKey, ...accountUpdateObject }
// Throw error from formatter validation
expect(() => caver.klay.sendTransaction(tx)).to.throw
}).timeout(200000)
// Update with failKey, roleTransactionKey and multisig.
it('CAVERJS-UNIT-TX-23