Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #644 from klaytn/release/v1.8.2
Browse files Browse the repository at this point in the history
[Master] release/v1.8.2 QA Sign-off
  • Loading branch information
jimni1222 authored Jun 20, 2022
2 parents 8d39c3c + 00fd8eb commit 5fc8373
Show file tree
Hide file tree
Showing 22 changed files with 869 additions and 859 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
#* @global-owner1 @global-owner2
* @jimni1222 @sirano11 @aeharvlee
* @jimni1222 @aeharvlee

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
Expand Down
1,233 changes: 576 additions & 657 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "caver-js",
"version": "1.8.1",
"version": "1.8.2",
"description": "caver-js is a JavaScript API library that allows developers to interact with a Klaytn node",
"main": "index.js",
"types": "types/index.d.ts",
Expand Down Expand Up @@ -70,11 +70,8 @@
"any-promise": "1.3.0",
"bignumber.js": "8.0.2",
"bn.js": "4.11.6",
"chai": "4.1.2",
"constants-browserify": "^1.0.0",
"crypto-browserify": "^3.12.0",
"docdash": "^1.2.0",
"dotenv": "8.2.0",
"elliptic": "6.5.4",
"eth-lib": "0.2.8",
"ethers": "5.4.1",
Expand All @@ -83,22 +80,16 @@
"http": "0.0.1-security",
"https": "^1.0.0",
"ipfs-http-client": "^49.0.4",
"jsdoc": "^3.6.7",
"lodash": "4.17.21",
"mocha": "8.3.2",
"multihashes": "4.0.2",
"node-fetch": "2.6.7",
"number-to-bn": "1.7.0",
"oboe": "2.1.3",
"os": "^0.1.2",
"request": "2.88.2",
"scrypt-js": "3.0.1",
"semver": "6.2.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"utf8": "2.1.1",
"uuid": "8.3.2",
"webpack": "^5.65.0",
"websocket": "1.0.31",
"xhr2-cookies": "1.1.0"
},
Expand All @@ -114,8 +105,11 @@
"babel-plugin-external-helpers": "6.22.0",
"babelrc-rollup": "3.0.0",
"browserify": "16.2.2",
"chai": "^4.1.2",
"chai-as-promised": "7.1.1",
"del": "3.0.0",
"docdash": "^1.2.0",
"dotenv": "^8.2.0",
"dtslint": "^3.4.2",
"eslint": "^8.2.0",
"eslint-config-airbnb": "^19.0.4",
Expand All @@ -125,17 +119,22 @@
"eslint-plugin-prettier": "3.1.1",
"eslint-plugin-react": "^7.28.0",
"exorcist": "2.0.0",
"jsdoc": "^3.6.7",
"jsdoc-typeof-plugin": "^1.0.0",
"jshint": "^2.13.4",
"mocha": "^8.3.2",
"nock": "10.0.6",
"node-fetch": "^2.6.7",
"nyc": "^15.1.0",
"path": "0.12.7",
"prettier": "1.18.2",
"request": "^2.88.2",
"sinon": "9.0.0",
"sinon-chai": "3.5.0",
"turndown": "^7.1.1",
"typescript": "^4.4.4",
"vinyl-source-stream": "2.0.0",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1"
}
}
4 changes: 4 additions & 0 deletions packages/caver-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const POLLINGTIMEOUT = AVERAGE_BLOCK_TIME * TIMEOUTBLOCK // ~average block time

const TransactionDecoder = require('../../caver-transaction/src/transactionDecoder/transactionDecoder')
const { TX_TYPE_STRING } = require('../../caver-transaction/src/transactionHelper/transactionHelper')
const { resolveRawKeyToAccountKey } = require('../../caver-klay/caver-klay-accounts/src/transactionType/account')

function Method(options) {
// call, name should be existed to create a method.
Expand Down Expand Up @@ -427,6 +428,9 @@ const buildSendRequestFunc = (defer, sendSignedTx, sendTxCallback) => (payload,
}
} else if (key === 'codeFormat') {
tx[key] = utils.hexToNumber(payload.params[0][key])
} else if (key === 'key' && _.isObject(payload.params[0][key])) {
// If key field is `AccountForUpdate`, resolve this to raw encoded account key string.
tx.key = resolveRawKeyToAccountKey(payload.params[0])
} else if (key === 'account') {
tx.key = payload.params[0][key].getRLPEncodingAccountKey()
} else if (key === 'chainId') {
Expand Down
27 changes: 25 additions & 2 deletions packages/caver-klay/caver-klay-accounts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1700,12 +1700,30 @@ function Wallet(accounts) {
this._accounts = accounts
this.length = 0
this.defaultKeyName = 'caverjs_wallet'
this.lastIndex = -1
}

Wallet.prototype._findSafeIndex = function(pointer) {
pointer = pointer || 0
if (_.has(this, pointer)) {
return this._findSafeIndex(pointer + 1)
while (this.lastIndex >= pointer) {
if (!_.has(this, pointer)) {
break
}
pointer++
}
if (this.lastIndex < pointer) {
this.lastIndex = pointer
}
return pointer
}

Wallet.prototype._findSafeLastIndex = function(pointer) {
pointer = this.lastIndex
while (pointer >= 0) {
if (_.has(this, pointer)) {
break
}
pointer--
}
return pointer
}
Expand Down Expand Up @@ -1905,6 +1923,11 @@ Wallet.prototype.remove = function(addressOrIndex) {

this.length--

// Update last index
if (account.index === this.lastIndex) {
this.lastIndex = this._findSafeLastIndex()
}

return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with the caver-js. If not, see <http://www.gnu.org/licenses/>.
*/

const _ = require('lodash')
const RLP = require('eth-lib/lib/rlp')
const Bytes = require('eth-lib/lib/bytes')
const utils = require('../../../../caver-utils')
Expand Down Expand Up @@ -136,6 +137,11 @@ function rlpEncodeForFeeDelegatedAccountUpdateWithRatio(transaction) {
function resolveRawKeyToAccountKey(transaction) {
// Handles the case where AccountForUpdate is set in key field in transaction object to update account.
if (transaction.key) {
// If the key field is a string,
// it means that the already encoded Account Key is passed as a parameter.
if (_.isString(transaction.key)) {
return transaction.key
}
if (transaction.from && transaction.from.toLowerCase() !== transaction.key.address.toLowerCase()) {
throw new Error('The value of the from field of the transaction does not match the address of AccountForUpdate.')
}
Expand Down Expand Up @@ -237,4 +243,5 @@ module.exports = {
rlpEncodeForFeeDelegatedAccountUpdate,
rlpEncodeForFeeDelegatedAccountUpdateWithRatio,
parseAccountKey,
resolveRawKeyToAccountKey,
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,36 @@ const TX_TYPE_TAG = {
'0x7802': TX_TYPE_STRING.TxTypeEthereumDynamicFee,
}

const TX_TYPE_TAG_LEGACY_TX_TYPES = {
ACCOUNT_UPDATE: TX_TYPE_TAG.TxTypeAccountUpdate,
FEE_DELEGATED_ACCOUNT_UPDATE: TX_TYPE_TAG.TxTypeFeeDelegatedAccountUpdate,
FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedAccountUpdateWithRatio,

VALUE_TRANFSER: TX_TYPE_TAG.TxTypeValueTransfer,
FEE_DELEGATED_VALUE_TRANSFER: TX_TYPE_TAG.TxTypeFeeDelegatedValueTransfer,
FEE_DELEGATED_VALUE_TRANSFER_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedValueTransferWithRatio,

VALUE_TRANSFER_MEMO: TX_TYPE_TAG.TxTypeValueTransferMemo,
FEE_DELEGATED_VALUE_TRANSFER_MEMO: TX_TYPE_TAG.TxTypeFeeDelegatedValueTransferMemo,
FEE_DELEGATED_VALUE_TRANSFER_MEMO_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedValueTransferMemoWithRatio,

SMART_CONTRACT_DEPLOY: TX_TYPE_TAG.TxTypeSmartContractDeploy,
FEE_DELEGATED_SMART_CONTRACT_DEPLOY: TX_TYPE_TAG.TxTypeFeeDelegatedSmartContractDeploy,
FEE_DELEGATED_SMART_CONTRACT_DEPLOY_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedSmartContractDeployWithRatio,

SMART_CONTRACT_EXECUTION: TX_TYPE_TAG.TxTypeSmartContractExecution,
FEE_DELEGATED_SMART_CONTRACT_EXECUTION: TX_TYPE_TAG.TxTypeFeeDelegatedSmartContractExecution,
FEE_DELEGATED_SMART_CONTRACT_EXECUTION_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedSmartContractExecutionWithRatio,

CANCEL: TX_TYPE_TAG.TxTypeCancel,
FEE_DELEGATED_CANCEL: TX_TYPE_TAG.TxTypeFeeDelegatedCancel,
FEE_DELEGATED_CANCEL_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedCancelWithRatio,

CHAIN_DATA_ANCHORING: TX_TYPE_TAG.TxTypeChainDataAnchoring,
FEE_DELEGATED_CHAIN_DATA_ANCHORING: TX_TYPE_TAG.TxTypeFeeDelegatedChainDataAnchoring,
FEE_DELEGATED_CHAIN_DATA_ANCHORING_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedChainDataAnchoringWithRatio,
}

const CODE_FORMAT = {
EVM: '0x0',
}
Expand All @@ -186,7 +216,12 @@ const CODE_FORMAT = {
* @return {number}
*/
const getTypeInt = type => {
return utils.hexToNumber(TX_TYPE_TAG[type])
let typeInt = TX_TYPE_TAG[type]
// If type int cannot be found from TX_TYPE_TAG, means old type string.
if (typeInt === undefined) {
typeInt = TX_TYPE_TAG_LEGACY_TX_TYPES[type]
}
return utils.hexToNumber(typeInt)
}

/**
Expand Down
11 changes: 11 additions & 0 deletions packages/caver-wallet/src/keyring/multipleKeyring.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ class MultipleKeyring {
this.keys = keys
}

/**
* @type {string}
*/
get type() {
return 'MultipleKeyring'
}

set type(t) {
throw new Error(`keyring type cannot be set.`)
}

/**
* @type {string}
*/
Expand Down
11 changes: 11 additions & 0 deletions packages/caver-wallet/src/keyring/roleBasedKeyring.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ class RoleBasedKeyring {
this.keys = keys
}

/**
* @type {string}
*/
get type() {
return 'RoleBasedKeyring'
}

set type(t) {
throw new Error(`keyring type cannot be set.`)
}

/**
* @type {string}
*/
Expand Down
11 changes: 11 additions & 0 deletions packages/caver-wallet/src/keyring/singleKeyring.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ class SingleKeyring {
this.key = key
}

/**
* @type {string}
*/
get type() {
return 'SingleKeyring'
}

set type(t) {
throw new Error(`keyring type cannot be set.`)
}

/**
* @type {string}
*/
Expand Down
2 changes: 1 addition & 1 deletion test/klaytn-integration-tests
3 changes: 2 additions & 1 deletion test/methodErrorHandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ describe('Error handling in Method package', () => {
type: 'SMART_CONTRACT_DEPLOY',
from: sender.address,
data: deployedData,
gas: 140000,
value: 0,
}
const estimated = await caver.rpc.klay.estimateGas(tx)
tx.gas = Math.floor(caver.utils.hexToNumber(estimated) * 0.8)
const expectedError = `contract creation code storage out of gas`
await expect(caver.klay.sendTransaction(tx)).to.be.rejectedWith(expectedError)
}).timeout(200000)
Expand Down
22 changes: 22 additions & 0 deletions test/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ describe('Personal RPC test', () => {
expect(receipt.type).to.equals('TxTypeLegacyTransaction')
}).timeout(50000)

// sendTransaction with account update tx
it('CAVERJS-UNIT-ETC-404: sendTransaction should format a transaction to send tx with account in Node.', async () => {
try {
// If account is already existed in node, return error.
const address = await caver.klay.personal.importRawKey(senderPrvKey, password)
expect(address.toLowerCase()).to.equals(senderAddress.toLowerCase())
} catch (e) {}

const receipt = await caver.klay.personal.sendTransaction(
{
type: 'ACCOUNT_UPDATE',
from: senderAddress,
key: caver.klay.accounts.createAccountForUpdateWithLegacyKey(senderAddress),
gas: 900000,
},
password
)
console.log(receipt)
expect(receipt).not.to.be.null
expect(receipt.type).to.equals('TxTypeAccountUpdate')
}).timeout(50000)

// signTransaction
it('CAVERJS-UNIT-ETC-088: signTransaction should send a signed transaction using an account in the node.', async () => {
const testAccount = caver.klay.accounts.create()
Expand Down
Loading

0 comments on commit 5fc8373

Please sign in to comment.