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 #397 from jimni1222/deployError
Browse files Browse the repository at this point in the history
Modified to throw error in deploy function
  • Loading branch information
jimni1222 authored Nov 19, 2020
2 parents ee91922 + ee07b30 commit df2b13a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "caver-js is a JavaScript API library that allows developers to interact with a Klaytn node",
"main": "index.js",
"scripts": {
"test": "npm run build && npm run transactionTest && mocha test/packages/caver.utils.js && mocha test/packages/caver.klay.net.js && npm run accountTest && npm run serTest && npm run walletTest",
"test": "npm run build && npm run transactionTest && mocha test/packages/caver.utils.js && mocha test/packages/caver.klay.net.js && npm run accountTest && npm run serTest && npm run walletTest && mocha test/contractError.js",
"build-all": "gulp all",
"build": "./node_modules/.bin/webpack --mode production",
"lint": "./node_modules/.bin/eslint './**/*.js'",
Expand All @@ -15,7 +15,7 @@
"rpcTest": "mocha test/packages/caver.rpc.js",
"transactionTest": "mocha test/packages/caver.transaction/*.js",
"txTest": "mocha test/methodErrorHandling.js && mocha test/sendSignedTransaction.js && mocha test/estimateComputationCost.js && mocha test/getTransactionReceipt.js && mocha test/setNonceWithPendingTag.js && mocha test/getTransaction.js && mocha test/setContractOptions.js && mocha test/encodeContractDeploy.js && mocha test/accounts.signTransaction.js && mocha test/sendTransactionCallback.js && mocha test/signWithMultiSig.js && mocha test/transactionType/legacyTransaction.js && mocha test/transactionType/valueTransfer* && mocha test/transactionType/accountUpdate.js && mocha test/transactionType/contract* && mocha test/transactionType/cancelTransaction.js && mocha test/transactionType/feeDelegated*",
"etcTest": "mocha test/reconnectTest.js && mocha test/packages/caver.utils.js && mocha test/confirmationListener.js && mocha test/hashMessage.js && mocha test/iban.* && mocha test/randomHex.js && mocha test/sha3.js && mocha test/toChecksumAddress.js && mocha test/unitMap.js && mocha test/default* && mocha test/getNodeInfo.js && mocha test/eventEmitter.js && mocha test/packages/caver.klay.net.js && mocha test/getNetworkType.js && mocha test/invalidResponse.js && mocha test/isContractDeployment.js && mocha test/personal.js && mocha test/multiProviderTest.js && mocha test/subscription.js && mocha test/supportsSubscriptions.js && mocha test/contract.once.js && mocha test/setProvider.js",
"etcTest": "mocha test/contractError.js && mocha test/reconnectTest.js && mocha test/packages/caver.utils.js && mocha test/confirmationListener.js && mocha test/hashMessage.js && mocha test/iban.* && mocha test/randomHex.js && mocha test/sha3.js && mocha test/toChecksumAddress.js && mocha test/unitMap.js && mocha test/default* && mocha test/getNodeInfo.js && mocha test/eventEmitter.js && mocha test/packages/caver.klay.net.js && mocha test/getNetworkType.js && mocha test/invalidResponse.js && mocha test/isContractDeployment.js && mocha test/personal.js && mocha test/multiProviderTest.js && mocha test/subscription.js && mocha test/supportsSubscriptions.js && mocha test/contract.once.js && mocha test/setProvider.js",
"accountKeyTest": "mocha test/scenarioTest/accountKeyPublic.js && mocha test/scenarioTest/accountKeyMultiSig.js && mocha test/scenarioTest/accountKeyRoleBased.js",
"kctTest": "mocha test/packages/caver.klay.KIP7.js && mocha test/packages/caver.klay.KIP17.js",
"intTxTest": "npm run intLEGACYTest && npm run intVTTest && npm run intVTMTest && npm run intACCUPTest && npm run intDEPLTest && npm run intEXETest && npm run intCANCELTest && npm run intFDTest && npm run intFDRTest",
Expand Down
10 changes: 4 additions & 6 deletions packages/caver-contract/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,10 @@ Contract.prototype.deploy = function(options, callback) {

// return error, if no "data" is specified
if (!options.data) {
return utils._fireError(
new Error('No "data" specified in neither the given options, nor the default options.'),
null,
null,
callback
)
const error = new Error('No "data" specified in neither the given options, nor the default options.')
if (callback) callback(error)

throw error
}

const constructor =
Expand Down
109 changes: 109 additions & 0 deletions test/contractError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
Copyright 2020 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 } = require('./extendedChai')

const testRPCURL = require('./testrpc')

const Caver = require('../index.js')

let caver

const abi = [
{
constant: true,
inputs: [],
name: 'count',
outputs: [
{
name: '',
type: 'uint256',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'getBlockNumber',
outputs: [
{
name: '',
type: 'uint256',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'addr',
outputs: [
{
name: '',
type: 'address',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: false,
inputs: [
{
name: '_str',
type: 'bytes32',
},
],
name: 'setAddress',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
{
constant: false,
inputs: [
{
name: '_count',
type: 'uint256',
},
],
name: 'setCount',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
]

describe('caver.contract error handling', () => {
before(() => {
caver = new Caver(testRPCURL)
})

it('CAVERJS-UNIT-ETC-254: contract.deploy throw error when data is not defined', async () => {
const contract = new caver.contract(abi)
expect(() => contract.deploy()).to.throw('No "data" specified in neither the given options, nor the default options.')
}).timeout(200000)
})

0 comments on commit df2b13a

Please sign in to comment.