diff --git a/packages/caver-kct/src/index.js b/packages/caver-kct/src/index.js index 84da2395..1d1a3844 100644 --- a/packages/caver-kct/src/index.js +++ b/packages/caver-kct/src/index.js @@ -16,6 +16,7 @@ along with the caver-js. If not, see . */ +const _ = require('lodash') const BaseKIP7 = require('./kip7') const BaseKIP17 = require('./kip17') const KIP37 = require('./kip37') @@ -71,23 +72,27 @@ class KCT { * The KIP7 instance deployed and returned through this function uses the keyringContainer instead of accounts. * @method deploy * @param {Object} tokenInfo The object that defines the name, symbol, decimals, and initialSupply of the token to deploy. - * @param {String} deployer The address of the account to deploy the KIP-7 token contract. + * @param {Object|String} sendOptions The address of the account to deploy the KIP-7 token contract or an object holding parameters that are required for sending a transaction. * @param {IWallet} wallet The wallet instance to sign and send a transaction. * @return {object} */ - static deploy(tokenInfo, deployer, wallet) { + static deploy(tokenInfo, sendOptions, wallet) { validateDeployParameterForKIP7(tokenInfo) const { name, symbol, decimals, initialSupply } = tokenInfo const kip7 = new KIP7() if (wallet !== undefined) kip7.setWallet(wallet) + // If sendOptions is string type, sendOptions means deployer's address + if (_.isString(sendOptions)) sendOptions = { from: sendOptions, gas: 4000000, value: 0 } + sendOptions.gas = sendOptions.gas !== undefined ? sendOptions.gas : 4000000 + return kip7 .deploy({ data: kip7ByteCode, arguments: [name, symbol, decimals, initialSupply], }) - .send({ from: deployer, gas: 4000000, value: 0 }) + .send(sendOptions) } /** @@ -132,23 +137,27 @@ class KCT { * The KIP17 instance deployed and returned through this function uses the keyringContainer instead of accounts. * @method deploy * @param {Object} tokenInfo The object that defines the name and symbol of the token to deploy. - * @param {String} deployer The address of the account to deploy the KIP-17 token contract. + * @param {Object|String} sendOptions The address of the account to deploy the KIP-17 token contract or an object holding parameters that are required for sending a transaction. * @param {IWallet} wallet The wallet instance to sign and send a transaction. * @return {object} */ - static deploy(tokenInfo, deployer, wallet) { + static deploy(tokenInfo, sendOptions, wallet) { validateDeployParameterForKIP17(tokenInfo) const { name, symbol } = tokenInfo const kip17 = new KIP17() if (wallet !== undefined) kip17.setWallet(wallet) + // If sendOptions is string type, sendOptions means deployer's address + if (_.isString(sendOptions)) sendOptions = { from: sendOptions, gas: 6600000, value: 0 } + sendOptions.gas = sendOptions.gas !== undefined ? sendOptions.gas : 6600000 + return kip17 .deploy({ data: kip17ByteCode, arguments: [name, symbol], }) - .send({ from: deployer, gas: 6600000, value: 0 }) + .send(sendOptions) } /** diff --git a/packages/caver-kct/src/kctHelper.js b/packages/caver-kct/src/kctHelper.js index d7b748f9..8c74976b 100644 --- a/packages/caver-kct/src/kctHelper.js +++ b/packages/caver-kct/src/kctHelper.js @@ -20,9 +20,11 @@ const _ = require('lodash') const BigNumber = require('bignumber.js') const { isBigNumber } = require('../../caver-utils') -async function determineSendParams(executableObj, sendParam, defaultFrom) { - let { from, gas } = sendParam - from = from || defaultFrom +async function determineSendParams(executableObj, sendParam, options) { + let sendOptions = {} + sendOptions = Object.assign(sendOptions, options) + sendOptions = Object.assign(sendOptions, sendParam) + const { from, gas, feeDelegation, feePayer, feeRatio } = sendOptions if (!from) throw new Error( `'from' is missing. Please pass the sender's address in sendParam.from or define default sender address at 'kctContract.options.from'.` @@ -33,10 +35,14 @@ async function determineSendParams(executableObj, sendParam, defaultFrom) { const originalGas = new BigNumber(estimated, 10) const bufferGas = new BigNumber(1.7, 10) - gas = Math.round(originalGas.times(bufferGas)) + sendOptions.gas = Math.round(originalGas.times(bufferGas)) } - return { from, gas, gasPrice: sendParam.gasPrice, value: sendParam.value } + if (feeDelegation === undefined && (feePayer || feeRatio !== undefined)) { + throw new Error('To use fee delegation with KCT, please set `feeDelegation` field to true.') + } + + return sendOptions } function formatParamForUint256(param) { diff --git a/packages/caver-kct/src/kip17.js b/packages/caver-kct/src/kip17.js index 9872679f..f507f92e 100644 --- a/packages/caver-kct/src/kip17.js +++ b/packages/caver-kct/src/kip17.js @@ -42,21 +42,25 @@ class KIP17 extends Contract { * * @method deploy * @param {Object} tokenInfo The object that defines the name and symbol of the token to deploy. - * @param {String} deployer The address of the account to deploy the KIP-17 token contract. + * @param {Object|String} sendOptions The address of the account to deploy the KIP-17 token contract or an object holding parameters that are required for sending a transaction. * @return {Object} */ - static deploy(tokenInfo, deployer) { + static deploy(tokenInfo, sendOptions) { validateDeployParameterForKIP17(tokenInfo) const { name, symbol } = tokenInfo const kip17 = new KIP17() + // If sendOptions is string type, sendOptions means deployer's address + if (_.isString(sendOptions)) sendOptions = { from: sendOptions, gas: 6600000, value: 0 } + sendOptions.gas = sendOptions.gas !== undefined ? sendOptions.gas : 6600000 + return kip17 .deploy({ data: kip17ByteCode, arguments: [name, symbol], }) - .send({ from: deployer, gas: 6600000, value: 0 }) + .send(sendOptions) } /** @@ -316,7 +320,7 @@ class KIP17 extends Contract { */ async approve(to, tokenId, sendParam = {}) { const executableObj = this.methods.approve(to, formatParamForUint256(tokenId)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -334,7 +338,7 @@ class KIP17 extends Contract { */ async setApprovalForAll(to, approved, sendParam = {}) { const executableObj = this.methods.setApprovalForAll(to, approved) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -352,7 +356,7 @@ class KIP17 extends Contract { */ async transferFrom(from, to, tokenId, sendParam = {}) { const executableObj = this.methods.transferFrom(from, to, formatParamForUint256(tokenId)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -387,7 +391,7 @@ class KIP17 extends Contract { ? this.methods.safeTransferFrom(from, to, formatParamForUint256(tokenId), data) : this.methods.safeTransferFrom(from, to, formatParamForUint256(tokenId)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -404,7 +408,7 @@ class KIP17 extends Contract { */ async addMinter(account, sendParam = {}) { const executableObj = this.methods.addMinter(account) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -420,7 +424,7 @@ class KIP17 extends Contract { */ async renounceMinter(sendParam = {}) { const executableObj = this.methods.renounceMinter() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -437,7 +441,7 @@ class KIP17 extends Contract { */ async mint(to, tokenId, sendParam = {}) { const executableObj = this.methods.mint(to, formatParamForUint256(tokenId)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -455,7 +459,7 @@ class KIP17 extends Contract { */ async mintWithTokenURI(to, tokenId, tokenURI, sendParam = {}) { const executableObj = this.methods.mintWithTokenURI(to, formatParamForUint256(tokenId), tokenURI) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -471,7 +475,7 @@ class KIP17 extends Contract { */ async burn(tokenId, sendParam = {}) { const executableObj = this.methods.burn(formatParamForUint256(tokenId)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -487,7 +491,7 @@ class KIP17 extends Contract { */ async pause(sendParam = {}) { const executableObj = this.methods.pause() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -505,7 +509,7 @@ class KIP17 extends Contract { */ async unpause(sendParam = {}) { const executableObj = this.methods.unpause() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -522,7 +526,7 @@ class KIP17 extends Contract { */ async addPauser(account, sendParam = {}) { const executableObj = this.methods.addPauser(account) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -538,10 +542,11 @@ class KIP17 extends Contract { */ async renouncePauser(sendParam = {}) { const executableObj = this.methods.renouncePauser() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } } +KIP17.byteCode = kip17ByteCode module.exports = KIP17 diff --git a/packages/caver-kct/src/kip37.js b/packages/caver-kct/src/kip37.js index 05d1a180..22961d8c 100644 --- a/packages/caver-kct/src/kip37.js +++ b/packages/caver-kct/src/kip37.js @@ -51,23 +51,27 @@ class KIP37 extends Contract { * * @method deploy * @param {Object} tokenInfo The object that defines the uri to deploy. - * @param {string} deployer The address of the account to deploy the KIP-37 token contract. + * @param {Object|String} sendOptions The address of the account to deploy the KIP-37 token contract or an object holding parameters that are required for sending a transaction. * @param {IWallet} [wallet] The wallet instance to sign and send a transaction. * @return {Object} */ - static deploy(tokenInfo, deployer, wallet) { + static deploy(tokenInfo, sendOptions, wallet) { validateDeployParameterForKIP37(tokenInfo) const { uri } = tokenInfo const kip37 = new KIP37() if (wallet !== undefined) kip37.setWallet(wallet) + // If sendOptions is string type, sendOptions means deployer's address + if (_.isString(sendOptions)) sendOptions = { from: sendOptions, gas: 7000000, value: 0 } + sendOptions.gas = sendOptions.gas !== undefined ? sendOptions.gas : 7000000 + return kip37 .deploy({ data: kip37ByteCode, arguments: [uri], }) - .send({ from: deployer, gas: 7000000, value: 0 }) + .send(sendOptions) } /** @@ -297,7 +301,7 @@ class KIP37 extends Contract { } const executableObj = this.methods.create(formatParamForUint256(id), formatParamForUint256(initialSupply), uri) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -315,7 +319,7 @@ class KIP37 extends Contract { */ async setApprovalForAll(operator, approved, sendParam = {}) { const executableObj = this.methods.setApprovalForAll(operator, approved) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -348,7 +352,7 @@ class KIP37 extends Contract { } const executableObj = this.methods.safeTransferFrom(from, to, formatParamForUint256(id), formatParamForUint256(amount), data) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -391,7 +395,7 @@ class KIP37 extends Contract { const executableObj = this.methods.safeBatchTransferFrom(from, to, formattedTokenIds, formattedTokenAmounts, data) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -425,7 +429,7 @@ class KIP37 extends Contract { executableObj = this.methods.mint(formatParamForUint256(id), toList, formatParamForUint256(values)) } - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -452,7 +456,7 @@ class KIP37 extends Contract { } const executableObj = this.methods.mintBatch(to, formattedTokenIds, formattedTokenValues) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -469,7 +473,7 @@ class KIP37 extends Contract { */ async addMinter(account, sendParam = {}) { const executableObj = this.methods.addMinter(account) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -485,7 +489,7 @@ class KIP37 extends Contract { */ async renounceMinter(sendParam = {}) { const executableObj = this.methods.renounceMinter() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -503,7 +507,7 @@ class KIP37 extends Contract { */ async burn(account, id, value, sendParam = {}) { const executableObj = this.methods.burn(account, formatParamForUint256(id), formatParamForUint256(value)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -530,7 +534,7 @@ class KIP37 extends Contract { } const executableObj = this.methods.burnBatch(account, formattedTokenIds, formattedTokenValues) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -554,7 +558,7 @@ class KIP37 extends Contract { } const executableObj = id !== undefined ? this.methods.pause(formatParamForUint256(id)) : this.methods.pause() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -578,7 +582,7 @@ class KIP37 extends Contract { } const executableObj = id !== undefined ? this.methods.unpause(formatParamForUint256(id)) : this.methods.unpause() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -595,7 +599,7 @@ class KIP37 extends Contract { */ async addPauser(account, sendParam = {}) { const executableObj = this.methods.addPauser(account) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -611,10 +615,11 @@ class KIP37 extends Contract { */ async renouncePauser(sendParam = {}) { const executableObj = this.methods.renouncePauser() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } } +KIP37.byteCode = kip37ByteCode module.exports = KIP37 diff --git a/packages/caver-kct/src/kip7.js b/packages/caver-kct/src/kip7.js index 0ffbc69b..0644ac8f 100644 --- a/packages/caver-kct/src/kip7.js +++ b/packages/caver-kct/src/kip7.js @@ -43,21 +43,25 @@ class KIP7 extends Contract { * * @method deploy * @param {Object} tokenInfo The object that defines the name, symbol, decimals, and initialSupply of the token to deploy. - * @param {String} deployer The address of the account to deploy the KIP-7 token contract. + * @param {Object|String} sendOptions The address of the account to deploy the KIP-7 token contract or an object holding parameters that are required for sending a transaction. * @return {Object} */ - static deploy(tokenInfo, deployer) { + static deploy(tokenInfo, sendOptions) { validateDeployParameterForKIP7(tokenInfo) const { name, symbol, decimals, initialSupply } = tokenInfo const kip7 = new KIP7() + // If sendOptions is string type, sendOptions means deployer's address + if (_.isString(sendOptions)) sendOptions = { from: sendOptions, gas: 4000000, value: 0 } + sendOptions.gas = sendOptions.gas !== undefined ? sendOptions.gas : 4000000 + return kip7 .deploy({ data: kip7ByteCode, arguments: [name, symbol, decimals, initialSupply], }) - .send({ from: deployer, gas: 4000000, value: 0 }) + .send(sendOptions) } /** @@ -272,7 +276,7 @@ class KIP7 extends Contract { */ async approve(spender, amount, sendParam = {}) { const executableObj = this.methods.approve(spender, formatParamForUint256(amount)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -289,7 +293,7 @@ class KIP7 extends Contract { */ async transfer(recipient, amount, sendParam = {}) { const executableObj = this.methods.transfer(recipient, formatParamForUint256(amount)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -308,7 +312,7 @@ class KIP7 extends Contract { */ async transferFrom(sender, recipient, amount, sendParam = {}) { const executableObj = this.methods.transferFrom(sender, recipient, formatParamForUint256(amount)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -342,7 +346,7 @@ class KIP7 extends Contract { ? this.methods.safeTransfer(recipient, formatParamForUint256(amount), data) : this.methods.safeTransfer(recipient, formatParamForUint256(amount)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -377,7 +381,7 @@ class KIP7 extends Contract { ? this.methods.safeTransferFrom(sender, recipient, formatParamForUint256(amount), data) : this.methods.safeTransferFrom(sender, recipient, formatParamForUint256(amount)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -395,7 +399,7 @@ class KIP7 extends Contract { */ async mint(account, amount, sendParam = {}) { const executableObj = this.methods.mint(account, formatParamForUint256(amount)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -412,7 +416,7 @@ class KIP7 extends Contract { */ async addMinter(account, sendParam = {}) { const executableObj = this.methods.addMinter(account) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -428,7 +432,7 @@ class KIP7 extends Contract { */ async renounceMinter(sendParam = {}) { const executableObj = this.methods.renounceMinter() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -444,7 +448,7 @@ class KIP7 extends Contract { */ async burn(amount, sendParam = {}) { const executableObj = this.methods.burn(formatParamForUint256(amount)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -461,7 +465,7 @@ class KIP7 extends Contract { */ async burnFrom(account, amount, sendParam = {}) { const executableObj = this.methods.burnFrom(account, formatParamForUint256(amount)) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -478,7 +482,7 @@ class KIP7 extends Contract { */ async addPauser(account, sendParam = {}) { const executableObj = this.methods.addPauser(account) - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -494,7 +498,7 @@ class KIP7 extends Contract { */ async pause(sendParam = {}) { const executableObj = this.methods.pause() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -512,7 +516,7 @@ class KIP7 extends Contract { */ async unpause(sendParam = {}) { const executableObj = this.methods.unpause() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } @@ -528,10 +532,11 @@ class KIP7 extends Contract { */ async renouncePauser(sendParam = {}) { const executableObj = this.methods.renouncePauser() - sendParam = await determineSendParams(executableObj, sendParam, this.options.from) + sendParam = await determineSendParams(executableObj, sendParam, this.options) return executableObj.send(sendParam) } } +KIP7.byteCode = kip7ByteCode module.exports = KIP7 diff --git a/test/packages/caver.kct.kip37.js b/test/packages/caver.kct.kip37.js index aa70ffab..f91de8ab 100644 --- a/test/packages/caver.kct.kip37.js +++ b/test/packages/caver.kct.kip37.js @@ -22,11 +22,13 @@ const _ = require('lodash') const testRPCURL = require('../testrpc') const { expect } = require('../extendedChai') +const { TX_TYPE_STRING } = require('../../packages/caver-transaction/src/transactionHelper/transactionHelper') const Caver = require('../../index.js') let caver let sender +let feePayer let testAccount let receiver const testAddresses = [] @@ -36,7 +38,7 @@ const tokenIds = [tokenId] const ownerMap = {} -let multiTokenAddress +let kip37Address const tokenURI = 'https://game.example/item-id/{id}.json' const tokenInfo = { uri: tokenURI } @@ -76,6 +78,14 @@ before(function(done) { caver.wallet.add(sender) ownerMap[sender.address] = [] + const feePayerPrvKey = + process.env.privateKey2 && String(process.env.privateKey2).indexOf('0x') === -1 + ? `0x${process.env.privateKey2}` + : process.env.privateKey2 + + feePayer = caver.wallet.keyring.createFromPrivateKey(feePayerPrvKey) + caver.wallet.add(feePayer) + prepareTestSetting().then(() => done()) }) @@ -91,7 +101,7 @@ describe('KIP37 token contract class test', () => { expect(account.accType).to.equal(2) expect(account.account.key.keyType).to.equal(3) - multiTokenAddress = deployed.options.address + kip37Address = deployed.options.address }).timeout(200000) it('CAVERJS-UNIT-KCT-161: should throw error when token information is insufficient or invalid', async () => { @@ -105,7 +115,7 @@ describe('KIP37 token contract class test', () => { context('kip37.clone', () => { it('CAVERJS-UNIT-KCT-162: should clone KIP37 instance with new token contract address', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const newTokenContract = caver.wallet.keyring.generate().address const cloned = token.clone(newTokenContract) @@ -117,7 +127,7 @@ describe('KIP37 token contract class test', () => { context('kip37.supportsInterface', () => { it('CAVERJS-UNIT-KCT-163: should return true if interfaceId is supported', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) expect(await token.supportsInterface('0x6433ca1f')).to.be.true // IKIP37 expect(await token.supportsInterface('0x0e89341c')).to.be.true // IKIP37MetatdataURI @@ -133,7 +143,7 @@ describe('KIP37 token contract class test', () => { context('kip37.create', () => { it('CAVERJS-UNIT-KCT-164: should create new token', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const created = await token.create(tokenId, 10000000000, tokenURI, { from: sender.address }) @@ -141,13 +151,13 @@ describe('KIP37 token contract class test', () => { expect(created.status).to.be.true expect(created.events).not.to.be.undefined expect(created.events.TransferSingle).not.to.be.undefined - expect(created.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(created.events.TransferSingle.address).to.equal(kip37Address) expect(created.events.URI).not.to.be.undefined - expect(created.events.URI.address).to.equal(multiTokenAddress) + expect(created.events.URI.address).to.equal(kip37Address) }).timeout(200000) it('CAVERJS-UNIT-KCT-165: should create new token with various type of tokenId and initialSupply', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let created = await token.create('0x1', '10000000000', tokenURI, { from: sender.address }) @@ -155,9 +165,9 @@ describe('KIP37 token contract class test', () => { expect(created.status).to.be.true expect(created.events).not.to.be.undefined expect(created.events.TransferSingle).not.to.be.undefined - expect(created.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(created.events.TransferSingle.address).to.equal(kip37Address) expect(created.events.URI).not.to.be.undefined - expect(created.events.URI.address).to.equal(multiTokenAddress) + expect(created.events.URI.address).to.equal(kip37Address) tokenIds.push(1) @@ -167,15 +177,15 @@ describe('KIP37 token contract class test', () => { expect(created.status).to.be.true expect(created.events).not.to.be.undefined expect(created.events.TransferSingle).not.to.be.undefined - expect(created.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(created.events.TransferSingle.address).to.equal(kip37Address) expect(created.events.URI).not.to.be.undefined - expect(created.events.URI.address).to.equal(multiTokenAddress) + expect(created.events.URI.address).to.equal(kip37Address) tokenIds.push(2) }).timeout(200000) it('CAVERJS-UNIT-KCT-215: should create new token without uri', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const created = await token.create(3, 10000000000, { from: sender.address }) @@ -183,12 +193,12 @@ describe('KIP37 token contract class test', () => { expect(created.status).to.be.true expect(created.events).not.to.be.undefined expect(created.events.TransferSingle).not.to.be.undefined - expect(created.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(created.events.TransferSingle.address).to.equal(kip37Address) expect(created.events.URI).to.be.undefined }).timeout(200000) it('CAVERJS-UNIT-KCT-216: should create new token with various type of tokenId and initialSupply without uri', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let created = await token.create('0x4', '10000000000', { from: sender.address }) @@ -196,7 +206,7 @@ describe('KIP37 token contract class test', () => { expect(created.status).to.be.true expect(created.events).not.to.be.undefined expect(created.events.TransferSingle).not.to.be.undefined - expect(created.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(created.events.TransferSingle.address).to.equal(kip37Address) expect(created.events.URI).to.be.undefined created = await token.create(new BigNumber(5), new BigNumber('10000000000'), { from: sender.address }) @@ -205,14 +215,14 @@ describe('KIP37 token contract class test', () => { expect(created.status).to.be.true expect(created.events).not.to.be.undefined expect(created.events.TransferSingle).not.to.be.undefined - expect(created.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(created.events.TransferSingle.address).to.equal(kip37Address) expect(created.events.URI).to.be.undefined }).timeout(200000) }) context('kip37.uri', () => { it('CAVERJS-UNIT-KCT-166: should return the uri of the specific token', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const uri = await token.uri(tokenId) @@ -220,7 +230,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-167: should return the uri of the specific token with various tokenId types', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) expect(await token.uri(caver.utils.toHex(tokenId))).to.equal( 'https://game.example/item-id/0000000000000000000000000000000000000000000000000000000000000000.json' @@ -233,7 +243,7 @@ describe('KIP37 token contract class test', () => { context('kip37.totalSupply', () => { it('CAVERJS-UNIT-KCT-168: should return the total supply of the specific token', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const totalSupply = await token.totalSupply(tokenId) @@ -241,7 +251,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-169: should return the total supply of the specific token with various tokenId types', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let totalSupply = await token.totalSupply(caver.utils.toHex(tokenId)) expect(totalSupply.eq(new BigNumber(10000000000))).to.be.true @@ -253,7 +263,7 @@ describe('KIP37 token contract class test', () => { context('kip37.mint', () => { it('CAVERJS-UNIT-KCT-170: should mint the specific token with single to and value', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const minted = await token.mint(testAccount.address, tokenId, 1, { from: sender.address }) @@ -261,7 +271,7 @@ describe('KIP37 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.TransferSingle).not.to.be.undefined - expect(minted.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(minted.events.TransferSingle.address).to.equal(kip37Address) expect(minted.events.TransferSingle.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferSingle.returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferSingle.returnValues.to.toLowerCase()).to.equal(testAccount.address.toLowerCase()) @@ -269,7 +279,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-171: should mint the specific token with multiple to and value', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const acct1 = caver.wallet.keyring.generate() const acct2 = caver.wallet.keyring.generate() @@ -287,17 +297,17 @@ describe('KIP37 token contract class test', () => { expect(minted.events).not.to.be.undefined expect(_.isArray(minted.events.TransferSingle)).to.be.true expect(minted.events.TransferSingle.length).to.equal(3) - expect(minted.events.TransferSingle[0].address).to.equal(multiTokenAddress) + expect(minted.events.TransferSingle[0].address).to.equal(kip37Address) expect(minted.events.TransferSingle[0].returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferSingle[0].returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferSingle[0].returnValues.to.toLowerCase()).to.equal(acct1.address.toLowerCase()) expect(minted.events.TransferSingle[0].returnValues.id).to.equal(tokenId.toString()) - expect(minted.events.TransferSingle[1].address).to.equal(multiTokenAddress) + expect(minted.events.TransferSingle[1].address).to.equal(kip37Address) expect(minted.events.TransferSingle[1].returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferSingle[1].returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferSingle[1].returnValues.to.toLowerCase()).to.equal(acct2.address.toLowerCase()) expect(minted.events.TransferSingle[1].returnValues.id).to.equal(tokenId.toString()) - expect(minted.events.TransferSingle[2].address).to.equal(multiTokenAddress) + expect(minted.events.TransferSingle[2].address).to.equal(kip37Address) expect(minted.events.TransferSingle[2].returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferSingle[2].returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferSingle[2].returnValues.to.toLowerCase()).to.equal(sender.address.toLowerCase()) @@ -320,17 +330,17 @@ describe('KIP37 token contract class test', () => { expect(minted.events).not.to.be.undefined expect(_.isArray(minted.events.TransferSingle)).to.be.true expect(minted.events.TransferSingle.length).to.equal(3) - expect(minted.events.TransferSingle[0].address).to.equal(multiTokenAddress) + expect(minted.events.TransferSingle[0].address).to.equal(kip37Address) expect(minted.events.TransferSingle[0].returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferSingle[0].returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferSingle[0].returnValues.to.toLowerCase()).to.equal(acct1.address.toLowerCase()) expect(minted.events.TransferSingle[0].returnValues.id).to.equal(tokenIds[1].toString()) - expect(minted.events.TransferSingle[1].address).to.equal(multiTokenAddress) + expect(minted.events.TransferSingle[1].address).to.equal(kip37Address) expect(minted.events.TransferSingle[1].returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferSingle[1].returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferSingle[1].returnValues.to.toLowerCase()).to.equal(acct2.address.toLowerCase()) expect(minted.events.TransferSingle[1].returnValues.id).to.equal(tokenIds[1].toString()) - expect(minted.events.TransferSingle[2].address).to.equal(multiTokenAddress) + expect(minted.events.TransferSingle[2].address).to.equal(kip37Address) expect(minted.events.TransferSingle[2].returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferSingle[2].returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferSingle[2].returnValues.to.toLowerCase()).to.equal(sender.address.toLowerCase()) @@ -340,7 +350,7 @@ describe('KIP37 token contract class test', () => { context('kip37.balanceOf', () => { it('CAVERJS-UNIT-KCT-172: should return the balance of account with specific token', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const balance = await token.balanceOf(testAccount.address, tokenId) @@ -348,7 +358,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-173: should return the balance of account with specific token with various token type', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let balance = await token.balanceOf(testAccount.address, caver.utils.toHex(tokenId)) expect(balance.eq(new BigNumber(1))).to.be.true @@ -360,7 +370,7 @@ describe('KIP37 token contract class test', () => { context('kip37.balanceOfBatch', () => { it('CAVERJS-UNIT-KCT-174: should return the balance of accounts with specific token', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const balances = await token.balanceOfBatch(testAddresses, [tokenIds[0], tokenIds[1], tokenIds[1]]) @@ -371,7 +381,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-175: should return the balance of accounts with specific token with various tokenId types', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const balances = await token.balanceOfBatch(testAddresses, [ caver.utils.toHex(tokenIds[0]), @@ -388,7 +398,7 @@ describe('KIP37 token contract class test', () => { context('kip37.setApprovalForAll', () => { it("CAVERJS-UNIT-KCT-176: should set approval of token operations for all of the caller's token", async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let approved = await token.setApprovalForAll(testAccount.address, true, { from: sender.address }) @@ -396,7 +406,7 @@ describe('KIP37 token contract class test', () => { expect(approved.status).to.be.true expect(approved.events).not.to.be.undefined expect(approved.events.ApprovalForAll).not.to.be.undefined - expect(approved.events.ApprovalForAll.address).to.equal(multiTokenAddress) + expect(approved.events.ApprovalForAll.address).to.equal(kip37Address) expect(approved.events.ApprovalForAll.returnValues.account.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(approved.events.ApprovalForAll.returnValues.operator.toLowerCase()).to.equal(testAccount.address) expect(approved.events.ApprovalForAll.returnValues.approved).to.be.true @@ -407,7 +417,7 @@ describe('KIP37 token contract class test', () => { expect(approved.status).to.be.true expect(approved.events).not.to.be.undefined expect(approved.events.ApprovalForAll).not.to.be.undefined - expect(approved.events.ApprovalForAll.address).to.equal(multiTokenAddress) + expect(approved.events.ApprovalForAll.address).to.equal(kip37Address) expect(approved.events.ApprovalForAll.returnValues.account.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(approved.events.ApprovalForAll.returnValues.operator.toLowerCase()).to.equal(sender.address) expect(approved.events.ApprovalForAll.returnValues.approved).to.be.true @@ -416,7 +426,7 @@ describe('KIP37 token contract class test', () => { context('kip37.isApprovedForAll', () => { it("CAVERJS-UNIT-KCT-177: should return an approval of token operations for all of the caller's token", async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const approved = await token.isApprovedForAll(sender.address, testAccount.address) @@ -426,7 +436,7 @@ describe('KIP37 token contract class test', () => { context('kip37.paused', () => { it("CAVERJS-UNIT-KCT-178: should return whether or not the token contract's transaction is paused (no parameter)", async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const paused = await token.paused() @@ -434,7 +444,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-179: should return whether or not the specific token is paused (with tokenId parameter)', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const paused = await token.paused(tokenId) @@ -442,7 +452,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-180: should return whether or not the specific token is paused (with various tokenId types parameter)', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let paused = await token.paused(caver.utils.toHex(tokenId)) expect(paused).to.be.false @@ -454,7 +464,7 @@ describe('KIP37 token contract class test', () => { context('kip37.isPauser', () => { it('CAVERJS-UNIT-KCT-181: should return whether the account is pauser or not', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let isPauser = await token.isPauser(sender.address) expect(isPauser).to.be.true @@ -466,7 +476,7 @@ describe('KIP37 token contract class test', () => { context('kip37.isMinter', () => { it('CAVERJS-UNIT-KCT-182: should return whether the account is minter or not', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let isMinter = await token.isMinter(sender.address) expect(isMinter).to.be.true @@ -478,7 +488,7 @@ describe('KIP37 token contract class test', () => { context('kip37.safeTransferFrom', () => { it('CAVERJS-UNIT-KCT-183: should transfer the token from owner to receiver', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const transfered = await token.safeTransferFrom(sender.address, receiver.address, tokenId, 1, 'data to send', { from: sender.address, @@ -488,7 +498,7 @@ describe('KIP37 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.TransferSingle).not.to.be.undefined - expect(transfered.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(transfered.events.TransferSingle.address).to.equal(kip37Address) expect(transfered.events.TransferSingle.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferSingle.returnValues.from.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferSingle.returnValues.to.toLowerCase()).to.equal(receiver.address.toLowerCase()) @@ -497,7 +507,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-184: should transfer the token from owner to receiver by approved operator', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const transfered = await token.safeTransferFrom( sender.address, @@ -514,7 +524,7 @@ describe('KIP37 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.TransferSingle).not.to.be.undefined - expect(transfered.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(transfered.events.TransferSingle.address).to.equal(kip37Address) expect(transfered.events.TransferSingle.returnValues.operator.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(transfered.events.TransferSingle.returnValues.from.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferSingle.returnValues.to.toLowerCase()).to.equal(receiver.address.toLowerCase()) @@ -523,7 +533,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-217: should transfer the token without data', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const transfered = await token.safeTransferFrom(sender.address, receiver.address, tokenId, 1, { from: sender.address, @@ -533,7 +543,7 @@ describe('KIP37 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.TransferSingle).not.to.be.undefined - expect(transfered.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(transfered.events.TransferSingle.address).to.equal(kip37Address) expect(transfered.events.TransferSingle.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferSingle.returnValues.from.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferSingle.returnValues.to.toLowerCase()).to.equal(receiver.address.toLowerCase()) @@ -544,7 +554,7 @@ describe('KIP37 token contract class test', () => { context('kip37.safeBatchTransferFrom', () => { it('CAVERJS-UNIT-KCT-185: should transfer the tokens from owner to receiver', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const ids = [tokenIds[0], tokenIds[1]] const values = [1, 2] @@ -556,7 +566,7 @@ describe('KIP37 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.TransferBatch).not.to.be.undefined - expect(transfered.events.TransferBatch.address).to.equal(multiTokenAddress) + expect(transfered.events.TransferBatch.address).to.equal(kip37Address) expect(transfered.events.TransferBatch.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferBatch.returnValues.from.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferBatch.returnValues.to.toLowerCase()).to.equal(receiver.address.toLowerCase()) @@ -571,7 +581,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-186: should transfer the tokens from owner to receiver by approved operator', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const ids = [tokenIds[0], tokenIds[1]] const values = [1, 2] @@ -583,7 +593,7 @@ describe('KIP37 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.TransferBatch).not.to.be.undefined - expect(transfered.events.TransferBatch.address).to.equal(multiTokenAddress) + expect(transfered.events.TransferBatch.address).to.equal(kip37Address) expect(transfered.events.TransferBatch.returnValues.operator.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(transfered.events.TransferBatch.returnValues.from.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferBatch.returnValues.to.toLowerCase()).to.equal(receiver.address.toLowerCase()) @@ -598,7 +608,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-218: should transfer the tokens without data', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const ids = [tokenIds[0], tokenIds[1]] const values = [1, 2] @@ -610,7 +620,7 @@ describe('KIP37 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.TransferBatch).not.to.be.undefined - expect(transfered.events.TransferBatch.address).to.equal(multiTokenAddress) + expect(transfered.events.TransferBatch.address).to.equal(kip37Address) expect(transfered.events.TransferBatch.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferBatch.returnValues.from.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(transfered.events.TransferBatch.returnValues.to.toLowerCase()).to.equal(receiver.address.toLowerCase()) @@ -627,7 +637,7 @@ describe('KIP37 token contract class test', () => { context('kip37.mintBatch', () => { it('CAVERJS-UNIT-KCT-187: should mint the specific tokens', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const ids = tokenIds const values = new Array(tokenIds.length).fill(10) @@ -639,7 +649,7 @@ describe('KIP37 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.TransferBatch).not.to.be.undefined - expect(minted.events.TransferBatch.address).to.equal(multiTokenAddress) + expect(minted.events.TransferBatch.address).to.equal(kip37Address) expect(minted.events.TransferBatch.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferBatch.returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferBatch.returnValues.to.toLowerCase()).to.equal(testAccount.address.toLowerCase()) @@ -654,7 +664,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-188: should mint the specific tokens with various tokenId types', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let ids = tokenIds.map(id => caver.utils.toHex(id)) let values = new Array(tokenIds.length).fill(caver.utils.toHex(10)) @@ -666,7 +676,7 @@ describe('KIP37 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.TransferBatch).not.to.be.undefined - expect(minted.events.TransferBatch.address).to.equal(multiTokenAddress) + expect(minted.events.TransferBatch.address).to.equal(kip37Address) expect(minted.events.TransferBatch.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferBatch.returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferBatch.returnValues.to.toLowerCase()).to.equal(testAccount.address.toLowerCase()) @@ -689,7 +699,7 @@ describe('KIP37 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.TransferBatch).not.to.be.undefined - expect(minted.events.TransferBatch.address).to.equal(multiTokenAddress) + expect(minted.events.TransferBatch.address).to.equal(kip37Address) expect(minted.events.TransferBatch.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(minted.events.TransferBatch.returnValues.from.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') expect(minted.events.TransferBatch.returnValues.to.toLowerCase()).to.equal(testAccount.address.toLowerCase()) @@ -706,7 +716,7 @@ describe('KIP37 token contract class test', () => { context('kip37.addMinter', () => { it('CAVERJS-UNIT-KCT-189: should add minter', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const added = await token.addMinter(testAccount.address, { from: sender.address }) @@ -714,7 +724,7 @@ describe('KIP37 token contract class test', () => { expect(added.status).to.be.true expect(added.events).not.to.be.undefined expect(added.events.MinterAdded).not.to.be.undefined - expect(added.events.MinterAdded.address).to.equal(multiTokenAddress) + expect(added.events.MinterAdded.address).to.equal(kip37Address) expect(added.events.MinterAdded.returnValues.account.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(await token.isMinter(testAccount.address)).to.be.true }).timeout(200000) @@ -722,7 +732,7 @@ describe('KIP37 token contract class test', () => { context('kip37.renounceMinter', () => { it('CAVERJS-UNIT-KCT-190: should renounce minter', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const removed = await token.renounceMinter({ from: testAccount.address }) @@ -730,7 +740,7 @@ describe('KIP37 token contract class test', () => { expect(removed.status).to.be.true expect(removed.events).not.to.be.undefined expect(removed.events.MinterRemoved).not.to.be.undefined - expect(removed.events.MinterRemoved.address).to.equal(multiTokenAddress) + expect(removed.events.MinterRemoved.address).to.equal(kip37Address) expect(removed.events.MinterRemoved.returnValues.account.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(await token.isMinter(testAccount.address)).to.be.false }).timeout(200000) @@ -738,7 +748,7 @@ describe('KIP37 token contract class test', () => { context('kip37.burn', () => { it('CAVERJS-UNIT-KCT-191: should burn the specific token', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const originalBalance = await token.balanceOf(sender.address, tokenIds[0]) const burned = await token.burn(sender.address, tokenIds[0], 1, { from: sender.address }) @@ -748,7 +758,7 @@ describe('KIP37 token contract class test', () => { expect(burned.status).to.be.true expect(burned.events).not.to.be.undefined expect(burned.events.TransferSingle).not.to.be.undefined - expect(burned.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(burned.events.TransferSingle.address).to.equal(kip37Address) expect(burned.events.TransferSingle.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(burned.events.TransferSingle.returnValues.from.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(burned.events.TransferSingle.returnValues.to.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') @@ -758,7 +768,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-192: should burn the specific token by approved operator', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const originalBalance = await token.balanceOf(sender.address, tokenIds[0]) const burned = await token.burn(sender.address, caver.utils.toHex(tokenIds[0]), '1', { from: testAccount.address }) @@ -768,7 +778,7 @@ describe('KIP37 token contract class test', () => { expect(burned.status).to.be.true expect(burned.events).not.to.be.undefined expect(burned.events.TransferSingle).not.to.be.undefined - expect(burned.events.TransferSingle.address).to.equal(multiTokenAddress) + expect(burned.events.TransferSingle.address).to.equal(kip37Address) expect(burned.events.TransferSingle.returnValues.operator.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(burned.events.TransferSingle.returnValues.from.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(burned.events.TransferSingle.returnValues.to.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') @@ -780,7 +790,7 @@ describe('KIP37 token contract class test', () => { context('kip37.burnBatch', () => { it('CAVERJS-UNIT-KCT-193: should burn the specific tokens', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const ids = tokenIds const values = new Array(ids.length).fill(1) @@ -794,7 +804,7 @@ describe('KIP37 token contract class test', () => { expect(burned.status).to.be.true expect(burned.events).not.to.be.undefined expect(burned.events.TransferBatch).not.to.be.undefined - expect(burned.events.TransferBatch.address).to.equal(multiTokenAddress) + expect(burned.events.TransferBatch.address).to.equal(kip37Address) expect(burned.events.TransferBatch.returnValues.operator.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(burned.events.TransferBatch.returnValues.from.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(burned.events.TransferBatch.returnValues.to.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') @@ -811,7 +821,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-194: should burn the specific tokens by approved operator', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const ids = tokenIds.map(id => caver.utils.toHex(id)) const values = new Array(ids.length).fill(caver.utils.toHex(1)) @@ -825,7 +835,7 @@ describe('KIP37 token contract class test', () => { expect(burned.status).to.be.true expect(burned.events).not.to.be.undefined expect(burned.events.TransferBatch).not.to.be.undefined - expect(burned.events.TransferBatch.address).to.equal(multiTokenAddress) + expect(burned.events.TransferBatch.address).to.equal(kip37Address) expect(burned.events.TransferBatch.returnValues.operator.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(burned.events.TransferBatch.returnValues.from.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(burned.events.TransferBatch.returnValues.to.toLowerCase()).to.equal('0x0000000000000000000000000000000000000000') @@ -844,7 +854,7 @@ describe('KIP37 token contract class test', () => { context('kip37.pause', () => { it('CAVERJS-UNIT-KCT-195: should pause the KIP-37 token contract (without tokenId parameter)', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const paused = await token.pause({ from: sender.address }) @@ -852,7 +862,7 @@ describe('KIP37 token contract class test', () => { expect(paused.status).to.be.true expect(paused.events).not.to.be.undefined expect(paused.events.Paused).not.to.be.undefined - expect(paused.events.Paused.address).to.equal(multiTokenAddress) + expect(paused.events.Paused.address).to.equal(kip37Address) expect(paused.events.Paused.returnValues.account.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(await token.paused()).to.be.true @@ -860,7 +870,7 @@ describe('KIP37 token contract class test', () => { }).timeout(200000) it('CAVERJS-UNIT-KCT-196: should pause the specific token', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const paused = await token.pause(tokenIds[0], { from: sender.address }) @@ -868,14 +878,14 @@ describe('KIP37 token contract class test', () => { expect(paused.status).to.be.true expect(paused.events).not.to.be.undefined expect(paused.events.Paused).not.to.be.undefined - expect(paused.events.Paused.address).to.equal(multiTokenAddress) + expect(paused.events.Paused.address).to.equal(kip37Address) expect(paused.events.Paused.returnValues.account.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(paused.events.Paused.returnValues.tokenId).to.equal(tokenIds[0].toString()) expect(await token.paused(tokenIds[0])).to.be.true }).timeout(200000) it('CAVERJS-UNIT-KCT-197: should pause the specific token with various tokenId types', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let paused = await token.pause(caver.utils.toHex(tokenIds[1]), { from: sender.address }) @@ -883,7 +893,7 @@ describe('KIP37 token contract class test', () => { expect(paused.status).to.be.true expect(paused.events).not.to.be.undefined expect(paused.events.Paused).not.to.be.undefined - expect(paused.events.Paused.address).to.equal(multiTokenAddress) + expect(paused.events.Paused.address).to.equal(kip37Address) expect(paused.events.Paused.returnValues.account.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(paused.events.Paused.returnValues.tokenId).to.equal(tokenIds[1].toString()) expect(await token.paused(tokenIds[1])).to.be.true @@ -894,7 +904,7 @@ describe('KIP37 token contract class test', () => { expect(paused.status).to.be.true expect(paused.events).not.to.be.undefined expect(paused.events.Paused).not.to.be.undefined - expect(paused.events.Paused.address).to.equal(multiTokenAddress) + expect(paused.events.Paused.address).to.equal(kip37Address) expect(paused.events.Paused.returnValues.account.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(paused.events.Paused.returnValues.tokenId).to.equal(tokenIds[2].toString()) expect(await token.paused(tokenIds[2])).to.be.true @@ -903,7 +913,7 @@ describe('KIP37 token contract class test', () => { context('kip37.unpause', () => { it('CAVERJS-UNIT-KCT-198: should unpause the KIP-37 token contract (without tokenId parameter)', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) await token.pause({ from: sender.address }) expect(await token.paused()).to.be.true @@ -914,12 +924,12 @@ describe('KIP37 token contract class test', () => { expect(unpaused.status).to.be.true expect(unpaused.events).not.to.be.undefined expect(unpaused.events.Unpaused).not.to.be.undefined - expect(unpaused.events.Unpaused.address).to.equal(multiTokenAddress) + expect(unpaused.events.Unpaused.address).to.equal(kip37Address) expect(unpaused.events.Unpaused.returnValues.account.toLowerCase()).to.equal(sender.address.toLowerCase()) }).timeout(200000) it('CAVERJS-UNIT-KCT-199: should unpause the specific token', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const paused = await token.unpause(tokenIds[0], { from: sender.address }) @@ -927,14 +937,14 @@ describe('KIP37 token contract class test', () => { expect(paused.status).to.be.true expect(paused.events).not.to.be.undefined expect(paused.events.Unpaused).not.to.be.undefined - expect(paused.events.Unpaused.address).to.equal(multiTokenAddress) + expect(paused.events.Unpaused.address).to.equal(kip37Address) expect(paused.events.Unpaused.returnValues.account.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(paused.events.Unpaused.returnValues.tokenId).to.equal(tokenIds[0].toString()) expect(await token.paused(tokenIds[0])).to.be.false }).timeout(200000) it('CAVERJS-UNIT-KCT-200: should unpause the specific token with various tokenId types', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let unpaused = await token.unpause(caver.utils.toHex(tokenIds[1]), { from: sender.address }) @@ -942,7 +952,7 @@ describe('KIP37 token contract class test', () => { expect(unpaused.status).to.be.true expect(unpaused.events).not.to.be.undefined expect(unpaused.events.Unpaused).not.to.be.undefined - expect(unpaused.events.Unpaused.address).to.equal(multiTokenAddress) + expect(unpaused.events.Unpaused.address).to.equal(kip37Address) expect(unpaused.events.Unpaused.returnValues.account.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(unpaused.events.Unpaused.returnValues.tokenId).to.equal(tokenIds[1].toString()) expect(await token.paused(tokenIds[1])).to.be.false @@ -953,7 +963,7 @@ describe('KIP37 token contract class test', () => { expect(unpaused.status).to.be.true expect(unpaused.events).not.to.be.undefined expect(unpaused.events.Unpaused).not.to.be.undefined - expect(unpaused.events.Unpaused.address).to.equal(multiTokenAddress) + expect(unpaused.events.Unpaused.address).to.equal(kip37Address) expect(unpaused.events.Unpaused.returnValues.account.toLowerCase()).to.equal(sender.address.toLowerCase()) expect(unpaused.events.Unpaused.returnValues.tokenId).to.equal(tokenIds[2].toString()) expect(await token.paused(tokenIds[2])).to.be.false @@ -962,7 +972,7 @@ describe('KIP37 token contract class test', () => { context('kip37.addPauser', () => { it('CAVERJS-UNIT-KCT-201: should add pauser', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const added = await token.addPauser(testAccount.address, { from: sender.address }) @@ -970,7 +980,7 @@ describe('KIP37 token contract class test', () => { expect(added.status).to.be.true expect(added.events).not.to.be.undefined expect(added.events.PauserAdded).not.to.be.undefined - expect(added.events.PauserAdded.address).to.equal(multiTokenAddress) + expect(added.events.PauserAdded.address).to.equal(kip37Address) expect(added.events.PauserAdded.returnValues.account.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(await token.isPauser(testAccount.address)).to.be.true }).timeout(200000) @@ -978,7 +988,7 @@ describe('KIP37 token contract class test', () => { context('kip37.renouncePauser', () => { it('CAVERJS-UNIT-KCT-202: should renounce pauser', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) const removed = await token.renouncePauser({ from: testAccount.address }) @@ -986,7 +996,7 @@ describe('KIP37 token contract class test', () => { expect(removed.status).to.be.true expect(removed.events).not.to.be.undefined expect(removed.events.PauserRemoved).not.to.be.undefined - expect(removed.events.PauserRemoved.address).to.equal(multiTokenAddress) + expect(removed.events.PauserRemoved.address).to.equal(kip37Address) expect(removed.events.PauserRemoved.returnValues.account.toLowerCase()).to.equal(testAccount.address.toLowerCase()) expect(await token.isPauser(testAccount.address)).to.be.false }).timeout(200000) @@ -994,7 +1004,7 @@ describe('KIP37 token contract class test', () => { context('KIP37.detectInterface', () => { it('CAVERJS-UNIT-KCT-211: should return valid object if contract is deployed by caver', async () => { - const token = new caver.kct.kip37(multiTokenAddress) + const token = new caver.kct.kip37(kip37Address) let detected = await token.detectInterface() expect(detected.IKIP37).to.be.true @@ -1004,7 +1014,7 @@ describe('KIP37 token contract class test', () => { expect(detected.IKIP37Pausable).to.be.true // Test static function - detected = await caver.kct.kip37.detectInterface(multiTokenAddress) + detected = await caver.kct.kip37.detectInterface(kip37Address) expect(detected.IKIP37).to.be.true expect(detected.IKIP37Metadata).to.be.true @@ -1122,4 +1132,245 @@ describe('KIP37 token contract class test', () => { await expect(caver.kct.kip37.detectInterface(contractAddress)).to.be.rejectedWith(expectedError) }).timeout(200000) }) + + context('KIP37 with fee delegation', () => { + const contractDeployFormatter = receipt => { + return receipt + } + + it('CAVERJS-UNIT-KCT-244: should send TxTypeSmartContractDeploy to deploy when feeDelegation is defined as true', async () => { + const deployed = await caver.kct.kip37.deploy( + { uri: tokenURI }, + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + contractDeployFormatter, + } + ) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.status).to.be.true + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-245: should send TxTypeFeeDelegatedSmartContractDeployWithRatio to deploy when feeRatio is defined and feeDelegation is defined as true', async () => { + const deployed = await caver.kct.kip37.deploy( + { uri: tokenURI }, + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + feeRatio: 30, + contractDeployFormatter, + } + ) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.status).to.be.true + expect(deployed.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeployWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-246: should send TxTypeSmartContractExecution to add minter when feeDelegation is defined as true', async () => { + const token = caver.kct.kip37.create(kip37Address) + + const added = await token.addMinter(caver.wallet.keyring.generate().address, { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + }) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-247: should send TxTypeSmartContractExecution to add minter when feeDelegation is defined as true via options', async () => { + const token = caver.kct.kip37.create(kip37Address) + + token.options.from = sender.address + token.options.feeDelegation = true + token.options.feePayer = feePayer.address + + const added = await token.addMinter(caver.wallet.keyring.generate().address) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-248: should send TxTypeFeeDelegatedSmartContractExecutionWithRatio to add minter when feeRatio is defined and feeDelegation is defined as true', async () => { + const token = caver.kct.kip37.create(kip37Address) + + const added = await token.addMinter(caver.wallet.keyring.generate().address, { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + feeRatio: 30, + }) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecutionWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-249: should send TxTypeFeeDelegatedSmartContractExecutionWithRatio to add minter when feeRatio is defined and feeDelegation is defined as true via options', async () => { + const token = caver.kct.kip37.create(kip37Address) + + token.options.from = sender.address + token.options.feeDelegation = true + token.options.feePayer = feePayer.address + token.options.feeRatio = 30 + + const added = await token.addMinter(caver.wallet.keyring.generate().address) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecutionWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-250: should overwrite contract.options when user send sendOptions parameter', async () => { + const token = caver.kct.kip37.create(kip37Address) + + token.options.from = feePayer.address + token.options.feeDelegation = false + token.options.feePayer = sender.address + token.options.feeRatio = 50 + + const added = await token.addMinter(caver.wallet.keyring.generate().address, { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + feeRatio: 30, + gas: 1231234, + }) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(added.gas).to.equal(caver.utils.numberToHex(1231234)) + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecutionWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-251: should sign and return signed TxTypeFeeDelegatedSmartContractDeploy', async () => { + const token = caver.kct.kip37.create() + + const signed = await token.sign( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'constructor', + caver.kct.kip37.byteCode, + tokenURI + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.signatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + + await caver.wallet.signAsFeePayer(feePayer.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-252: should sign as fee payer and return signed TxTypeFeeDelegatedSmartContractDeploy', async () => { + const token = caver.kct.kip37.create() + + const signed = await token.signAsFeePayer( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'constructor', + caver.kct.kip37.byteCode, + tokenURI + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.feePayerSignatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + + await caver.wallet.sign(sender.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-253: should sign and return signed TxTypeFeeDelegatedSmartContractExecution', async () => { + const token = caver.kct.kip37.create(kip37Address) + + const signed = await token.sign( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'addMinter', + caver.wallet.keyring.generate().address + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.signatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + + await caver.wallet.signAsFeePayer(feePayer.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-254: should sign as fee payer and return signed TxTypeFeeDelegatedSmartContractExecution', async () => { + const token = caver.kct.kip37.create(kip37Address) + + const signed = await token.signAsFeePayer( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'addMinter', + caver.wallet.keyring.generate().address + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.feePayerSignatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + + await caver.wallet.sign(sender.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + }) }) diff --git a/test/packages/caver.klay.KIP17.js b/test/packages/caver.klay.KIP17.js index 2c96d4a3..ff4e1e89 100644 --- a/test/packages/caver.klay.KIP17.js +++ b/test/packages/caver.klay.KIP17.js @@ -21,6 +21,7 @@ const BigNumber = require('bignumber.js') const testRPCURL = require('../testrpc') const { expect } = require('../extendedChai') +const { TX_TYPE_STRING } = require('../../packages/caver-transaction/src/transactionHelper/transactionHelper') const Caver = require('../../index.js') @@ -28,6 +29,7 @@ let caver let caver2 let kip17s let sender +let feePayer let testAccount let receiver @@ -35,7 +37,7 @@ let tokenId = 0 const ownerMap = {} -let nonFungibleTokenAddress +let kip17Address const tokenInfo = { name: 'Jasmine', @@ -82,6 +84,14 @@ before(function(done) { caver.wallet.add(sender) ownerMap[sender.address] = [] + const feePayerPrvKey = + process.env.privateKey2 && String(process.env.privateKey2).indexOf('0x') === -1 + ? `0x${process.env.privateKey2}` + : process.env.privateKey2 + + feePayer = caver.wallet.keyring.createFromPrivateKey(feePayerPrvKey) + caver.wallet.add(feePayer) + caver2.klay.accounts.wallet.add(senderPrvKey) kip17s = [caver.kct.kip17, caver2.klay.KIP17] @@ -102,7 +112,7 @@ describe('KIP17 token contract class test', () => { expect(account.accType).to.equals(2) expect(account.account.key.keyType).to.equals(3) - nonFungibleTokenAddress = deployed.options.address + kip17Address = deployed.options.address } }).timeout(200000) @@ -126,7 +136,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.clone', () => { it('CAVERJS-UNIT-KCT-064: should clone KIP17 instance with new token contract address', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const newTokenContract = caver.klay.accounts.create().address const cloned = token.clone(newTokenContract) @@ -140,7 +150,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.name', () => { it('CAVERJS-UNIT-KCT-065: should call name method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const name = await token.name() @@ -152,7 +162,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.symbol', () => { it('CAVERJS-UNIT-KCT-066: should call symbol method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const symbol = await token.symbol() @@ -165,7 +175,7 @@ describe('KIP17 token contract class test', () => { let expectedTotal = 0 it('CAVERJS-UNIT-KCT-067: should call totalSupply method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let totalSupply = await token.totalSupply() expect(totalSupply.eq(expectedTotal)).to.be.true @@ -184,7 +194,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.tokenURI', () => { it('CAVERJS-UNIT-KCT-068: should call tokenURI method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let uri = await token.tokenURI(new BigNumber(0)) expect(uri).to.equals(tokenURI) @@ -201,7 +211,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.tokenOfOwnerByIndex', () => { it('CAVERJS-UNIT-KCT-069: should call tokenOfOwnerByIndex method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const tokenByIndex = await token.tokenOfOwnerByIndex(sender.address, 0) expect(tokenByIndex.eq(0)).to.be.true @@ -212,7 +222,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.tokenByIndex', () => { it('CAVERJS-UNIT-KCT-070: should call tokenByIndex method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let tokenByIndex = await token.tokenByIndex(0) expect(tokenByIndex.eq(0)).to.be.true @@ -230,7 +240,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.balanceOf', () => { it('CAVERJS-UNIT-KCT-071: should call balanceOf method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let balance = await token.balanceOf(sender.address) expect(balance.eq(0)).to.be.false @@ -244,7 +254,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.ownerOf', () => { it('CAVERJS-UNIT-KCT-072: should call balanceOf method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let owner = await token.ownerOf('0') expect(owner.toLowerCase()).to.equals(sender.address.toLowerCase()) @@ -259,7 +269,7 @@ describe('KIP17 token contract class test', () => { let approvedId = 0 it('CAVERJS-UNIT-KCT-073: should call getApproved method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let approved = await token.getApproved(approvedId) expect(approved).to.equals('0x0000000000000000000000000000000000000000') @@ -276,7 +286,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.isApprovedForAll', () => { it('CAVERJS-UNIT-KCT-074: should call isApprovedForAll method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let isApprovedForAll = await token.isApprovedForAll(sender.address, testAccount.address) expect(isApprovedForAll).to.be.false @@ -294,7 +304,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.isMinter', () => { it('CAVERJS-UNIT-KCT-075: should call isMinter method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let isMinter = await token.isMinter(sender.address) expect(isMinter).to.be.true @@ -318,7 +328,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.paused', () => { it('CAVERJS-UNIT-KCT-076: should call paused method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let paused = await token.paused() expect(paused).to.be.false @@ -339,7 +349,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.isPauser', () => { it('CAVERJS-UNIT-KCT-077: should call isPauser method', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let isPauser = await token.isPauser(sender.address) expect(isPauser).to.be.true @@ -363,7 +373,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.approve', () => { it('CAVERJS-UNIT-KCT-078: should send transaction for calling approve method and set approve with token id without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -378,7 +388,7 @@ describe('KIP17 token contract class test', () => { expect(approved.status).to.be.true expect(approved.events).not.to.be.undefined expect(approved.events.Approval).not.to.be.undefined - expect(approved.events.Approval.address).to.equals(nonFungibleTokenAddress) + expect(approved.events.Approval.address).to.equals(kip17Address) const getApproved = await token.getApproved(mintedTokenId) @@ -388,7 +398,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-079: should send transaction for calling approve method and set approve with token id with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -400,7 +410,7 @@ describe('KIP17 token contract class test', () => { expect(approved.status).to.be.true expect(approved.events).not.to.be.undefined expect(approved.events.Approval).not.to.be.undefined - expect(approved.events.Approval.address).to.equals(nonFungibleTokenAddress) + expect(approved.events.Approval.address).to.equals(kip17Address) const getApproved = await token.getApproved(mintedTokenId) @@ -410,7 +420,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-080: should send transaction for calling approve method and set approve with token id with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -424,7 +434,7 @@ describe('KIP17 token contract class test', () => { expect(approved.status).to.be.true expect(approved.events).not.to.be.undefined expect(approved.events.Approval).not.to.be.undefined - expect(approved.events.Approval.address).to.equals(nonFungibleTokenAddress) + expect(approved.events.Approval.address).to.equals(kip17Address) const getApproved = await token.getApproved(mintedTokenId) @@ -434,7 +444,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-081: should send transaction for calling approve method and set approve with token id with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -452,7 +462,7 @@ describe('KIP17 token contract class test', () => { expect(approved.status).to.be.true expect(approved.events).not.to.be.undefined expect(approved.events.Approval).not.to.be.undefined - expect(approved.events.Approval.address).to.equals(nonFungibleTokenAddress) + expect(approved.events.Approval.address).to.equals(kip17Address) const getApproved = await token.getApproved(mintedTokenId) @@ -464,7 +474,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.setApprovalForAll', () => { it('CAVERJS-UNIT-KCT-082: should send transaction for calling setApprovalForAll method and set approve with all token without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const testKeyring = caver.wallet.keyring.generate() @@ -476,7 +486,7 @@ describe('KIP17 token contract class test', () => { expect(setApprovalForAll.status).to.be.true expect(setApprovalForAll.events).not.to.be.undefined expect(setApprovalForAll.events.ApprovalForAll).not.to.be.undefined - expect(setApprovalForAll.events.ApprovalForAll.address).to.equals(nonFungibleTokenAddress) + expect(setApprovalForAll.events.ApprovalForAll.address).to.equals(kip17Address) const isApprovedForAll = await token.isApprovedForAll(sender.address, testKeyring.address) @@ -486,7 +496,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-083: should send transaction for calling setApprovalForAll method and set approve with all token with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const testKeyring = caver.wallet.keyring.generate() @@ -495,7 +505,7 @@ describe('KIP17 token contract class test', () => { expect(setApprovalForAll.status).to.be.true expect(setApprovalForAll.events).not.to.be.undefined expect(setApprovalForAll.events.ApprovalForAll).not.to.be.undefined - expect(setApprovalForAll.events.ApprovalForAll.address).to.equals(nonFungibleTokenAddress) + expect(setApprovalForAll.events.ApprovalForAll.address).to.equals(kip17Address) const isApprovedForAll = await token.isApprovedForAll(sender.address, testKeyring.address) @@ -505,7 +515,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-084: should send transaction for calling setApprovalForAll method and set approve with all token with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const testKeyring = caver.wallet.keyring.generate() @@ -519,7 +529,7 @@ describe('KIP17 token contract class test', () => { expect(setApprovalForAll.status).to.be.true expect(setApprovalForAll.events).not.to.be.undefined expect(setApprovalForAll.events.ApprovalForAll).not.to.be.undefined - expect(setApprovalForAll.events.ApprovalForAll.address).to.equals(nonFungibleTokenAddress) + expect(setApprovalForAll.events.ApprovalForAll.address).to.equals(kip17Address) const isApprovedForAll = await token.isApprovedForAll(sender.address, testKeyring.address) @@ -529,7 +539,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-085: should send transaction for calling setApprovalForAll method and set approve with all token with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const testKeyring = caver.wallet.keyring.generate() @@ -544,7 +554,7 @@ describe('KIP17 token contract class test', () => { expect(setApprovalForAll.status).to.be.true expect(setApprovalForAll.events).not.to.be.undefined expect(setApprovalForAll.events.ApprovalForAll).not.to.be.undefined - expect(setApprovalForAll.events.ApprovalForAll.address).to.equals(nonFungibleTokenAddress) + expect(setApprovalForAll.events.ApprovalForAll.address).to.equals(kip17Address) const isApprovedForAll = await token.isApprovedForAll(sender.address, testKeyring.address) @@ -556,7 +566,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.transferFrom', () => { it('CAVERJS-UNIT-KCT-086: should send transaction to transfer token and trigger Transfer event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -574,7 +584,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenIdToTransfer) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -583,7 +593,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-087: should send transaction to transfer token and trigger Transfer event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -603,7 +613,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenIdToTransfer) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -612,7 +622,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-088: should send transaction to transfer token and trigger Transfer event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -632,7 +642,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenIdToTransfer) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -641,7 +651,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-089: should send transaction to transfer token and trigger Transfer event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -662,7 +672,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenIdToTransfer) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -673,7 +683,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.safeTransferFrom', () => { it('CAVERJS-UNIT-KCT-090: should send token via safeTransferFrom without data and trigger Transfer event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -690,7 +700,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(mintedTokenId) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -699,7 +709,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-091: should send token via safeTransferFrom without data and trigger Transfer event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -718,7 +728,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(mintedTokenId) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -727,7 +737,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-092: should send token via safeTransferFrom without data and trigger Transfer event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -746,7 +756,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(mintedTokenId) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -755,7 +765,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-093: should send token via safeTransferFrom without data and trigger Transfer event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -775,7 +785,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(mintedTokenId) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -784,7 +794,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-094: should send token via safeTransferFrom with data and trigger Transfer event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -807,7 +817,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(mintedTokenId) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -816,7 +826,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-095: should send token via safeTransferFrom with data and trigger Transfer event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -841,7 +851,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(mintedTokenId) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -850,7 +860,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-096: should send token via safeTransferFrom with data and trigger Transfer event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -875,7 +885,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(mintedTokenId) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -884,7 +894,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-097: should send token via safeTransferFrom with data and trigger Transfer event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const mintedTokenId = tokenId await token.mintWithTokenURI(sender.address, mintedTokenId, tokenURI, { from: sender.address }) @@ -912,7 +922,7 @@ describe('KIP17 token contract class test', () => { expect(transfered.status).to.be.true expect(transfered.events).not.to.be.undefined expect(transfered.events.Transfer).not.to.be.undefined - expect(transfered.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(transfered.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(mintedTokenId) expect(owner.toLowerCase()).to.be.equals(receiver.address.toLowerCase()) @@ -923,7 +933,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.addMinter', () => { it('CAVERJS-UNIT-KCT-098: should send transaction for adding minter and trigger MinterAdded event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const newMinter = caver.klay.accounts.create().address expect(await token.isMinter(newMinter)).to.be.false @@ -936,7 +946,7 @@ describe('KIP17 token contract class test', () => { expect(minterAdded.status).to.be.true expect(minterAdded.events).not.to.be.undefined expect(minterAdded.events.MinterAdded).not.to.be.undefined - expect(minterAdded.events.MinterAdded.address).to.equals(nonFungibleTokenAddress) + expect(minterAdded.events.MinterAdded.address).to.equals(kip17Address) expect(await token.isMinter(newMinter)).to.be.true } @@ -944,7 +954,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-099: should send transaction for adding minter and trigger MinterAdded event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const newMinter = caver.klay.accounts.create().address expect(await token.isMinter(newMinter)).to.be.false @@ -954,7 +964,7 @@ describe('KIP17 token contract class test', () => { expect(minterAdded.status).to.be.true expect(minterAdded.events).not.to.be.undefined expect(minterAdded.events.MinterAdded).not.to.be.undefined - expect(minterAdded.events.MinterAdded.address).to.equals(nonFungibleTokenAddress) + expect(minterAdded.events.MinterAdded.address).to.equals(kip17Address) expect(await token.isMinter(newMinter)).to.be.true } @@ -962,7 +972,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-100: should send transaction for adding minter and trigger MinterAdded event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const newMinter = caver.klay.accounts.create().address expect(await token.isMinter(newMinter)).to.be.false @@ -974,7 +984,7 @@ describe('KIP17 token contract class test', () => { expect(minterAdded.status).to.be.true expect(minterAdded.events).not.to.be.undefined expect(minterAdded.events.MinterAdded).not.to.be.undefined - expect(minterAdded.events.MinterAdded.address).to.equals(nonFungibleTokenAddress) + expect(minterAdded.events.MinterAdded.address).to.equals(kip17Address) expect(await token.isMinter(newMinter)).to.be.true } @@ -982,7 +992,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-101: should send transaction for adding minter and trigger MinterAdded event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const newMinter = caver.klay.accounts.create().address expect(await token.isMinter(newMinter)).to.be.false @@ -996,7 +1006,7 @@ describe('KIP17 token contract class test', () => { expect(minterAdded.status).to.be.true expect(minterAdded.events).not.to.be.undefined expect(minterAdded.events.MinterAdded).not.to.be.undefined - expect(minterAdded.events.MinterAdded.address).to.equals(nonFungibleTokenAddress) + expect(minterAdded.events.MinterAdded.address).to.equals(kip17Address) expect(await token.isMinter(newMinter)).to.be.true } @@ -1006,7 +1016,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.renounceMinter', () => { it('CAVERJS-UNIT-KCT-102: should send transaction for removing minter and trigger MinterRemoved event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.addMinter(testAccount.address, { from: sender.address }) expect(await token.isMinter(testAccount.address)).to.be.true @@ -1019,7 +1029,7 @@ describe('KIP17 token contract class test', () => { expect(minterRemoved.status).to.be.true expect(minterRemoved.events).not.to.be.undefined expect(minterRemoved.events.MinterRemoved).not.to.be.undefined - expect(minterRemoved.events.MinterRemoved.address).to.equals(nonFungibleTokenAddress) + expect(minterRemoved.events.MinterRemoved.address).to.equals(kip17Address) expect(await token.isMinter(testAccount.address)).to.be.false } @@ -1027,7 +1037,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-103: should send transaction for removing minter and trigger MinterRemoved event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.addMinter(testAccount.address, { from: sender.address }) expect(await token.isMinter(testAccount.address)).to.be.true @@ -1037,7 +1047,7 @@ describe('KIP17 token contract class test', () => { expect(minterRemoved.status).to.be.true expect(minterRemoved.events).not.to.be.undefined expect(minterRemoved.events.MinterRemoved).not.to.be.undefined - expect(minterRemoved.events.MinterRemoved.address).to.equals(nonFungibleTokenAddress) + expect(minterRemoved.events.MinterRemoved.address).to.equals(kip17Address) expect(await token.isMinter(testAccount.address)).to.be.false } @@ -1045,7 +1055,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-104: should send transaction for removing minter and trigger MinterRemoved event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.addMinter(testAccount.address, { from: sender.address }) expect(await token.isMinter(testAccount.address)).to.be.true @@ -1057,7 +1067,7 @@ describe('KIP17 token contract class test', () => { expect(minterRemoved.status).to.be.true expect(minterRemoved.events).not.to.be.undefined expect(minterRemoved.events.MinterRemoved).not.to.be.undefined - expect(minterRemoved.events.MinterRemoved.address).to.equals(nonFungibleTokenAddress) + expect(minterRemoved.events.MinterRemoved.address).to.equals(kip17Address) expect(await token.isMinter(testAccount.address)).to.be.false } @@ -1065,7 +1075,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-105: should send transaction for removing minter and trigger MinterRemoved event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.addMinter(testAccount.address, { from: sender.address }) expect(await token.isMinter(testAccount.address)).to.be.true @@ -1079,7 +1089,7 @@ describe('KIP17 token contract class test', () => { expect(minterRemoved.status).to.be.true expect(minterRemoved.events).not.to.be.undefined expect(minterRemoved.events.MinterRemoved).not.to.be.undefined - expect(minterRemoved.events.MinterRemoved.address).to.equals(nonFungibleTokenAddress) + expect(minterRemoved.events.MinterRemoved.address).to.equals(kip17Address) expect(await token.isMinter(testAccount.address)).to.be.false } @@ -1089,7 +1099,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.mintWithTokenURI', () => { it('CAVERJS-UNIT-KCT-106: should send transaction for minting and trigger Transfer event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const originalSupply = await token.totalSupply() @@ -1101,7 +1111,7 @@ describe('KIP17 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.Transfer).not.to.be.undefined - expect(minted.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(minted.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenId) expect(owner.toLowerCase()).to.equals(testAccount.address.toLowerCase()) @@ -1115,7 +1125,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-107: should send transaction for minting and trigger Transfer event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const originalSupply = await token.totalSupply() @@ -1124,7 +1134,7 @@ describe('KIP17 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.Transfer).not.to.be.undefined - expect(minted.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(minted.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenId) expect(owner.toLowerCase()).to.equals(testAccount.address.toLowerCase()) @@ -1138,7 +1148,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-108: should send transaction for minting and trigger Transfer event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const originalSupply = await token.totalSupply() @@ -1152,7 +1162,7 @@ describe('KIP17 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.Transfer).not.to.be.undefined - expect(minted.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(minted.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenId) expect(owner.toLowerCase()).to.equals(testAccount.address.toLowerCase()) @@ -1166,7 +1176,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-109: should send transaction for minting and trigger Transfer event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const originalSupply = await token.totalSupply() @@ -1179,7 +1189,7 @@ describe('KIP17 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.Transfer).not.to.be.undefined - expect(minted.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(minted.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenId) expect(owner.toLowerCase()).to.equals(testAccount.address.toLowerCase()) @@ -1195,7 +1205,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.burn', () => { it('CAVERJS-UNIT-KCT-110: should send transaction for burning and trigger Transfer event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.mintWithTokenURI(sender.address, tokenId, tokenURI, { from: sender.address }) @@ -1209,7 +1219,7 @@ describe('KIP17 token contract class test', () => { expect(burned.status).to.be.true expect(burned.events).not.to.be.undefined expect(burned.events.Transfer).not.to.be.undefined - expect(burned.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(burned.events.Transfer.address).to.equals(kip17Address) const afterSupply = await token.totalSupply() expect(Number(originalSupply) - Number(afterSupply)).to.be.equals(1) @@ -1219,7 +1229,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-111: should send transaction for burning and trigger Transfer event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.mintWithTokenURI(sender.address, tokenId, tokenURI, { from: sender.address }) @@ -1230,7 +1240,7 @@ describe('KIP17 token contract class test', () => { expect(burned.status).to.be.true expect(burned.events).not.to.be.undefined expect(burned.events.Transfer).not.to.be.undefined - expect(burned.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(burned.events.Transfer.address).to.equals(kip17Address) const afterSupply = await token.totalSupply() expect(Number(originalSupply) - Number(afterSupply)).to.be.equals(1) @@ -1240,7 +1250,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-112: should send transaction for burning and trigger Transfer event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.mintWithTokenURI(sender.address, tokenId, tokenURI, { from: sender.address }) @@ -1253,7 +1263,7 @@ describe('KIP17 token contract class test', () => { expect(burned.status).to.be.true expect(burned.events).not.to.be.undefined expect(burned.events.Transfer).not.to.be.undefined - expect(burned.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(burned.events.Transfer.address).to.equals(kip17Address) const afterSupply = await token.totalSupply() expect(Number(originalSupply) - Number(afterSupply)).to.be.equals(1) @@ -1263,7 +1273,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-113: should send transaction for burning and trigger Transfer event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.mintWithTokenURI(sender.address, tokenId, tokenURI, { from: sender.address }) @@ -1278,7 +1288,7 @@ describe('KIP17 token contract class test', () => { expect(burned.status).to.be.true expect(burned.events).not.to.be.undefined expect(burned.events.Transfer).not.to.be.undefined - expect(burned.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(burned.events.Transfer.address).to.equals(kip17Address) const afterSupply = await token.totalSupply() expect(Number(originalSupply) - Number(afterSupply)).to.be.equals(1) @@ -1290,7 +1300,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.pause', () => { it('CAVERJS-UNIT-KCT-114: should send transaction for pausing without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) // set deafult from address in kip17 instance token.options.from = sender.address @@ -1300,7 +1310,7 @@ describe('KIP17 token contract class test', () => { expect(doPause.status).to.be.true expect(doPause.events).not.to.be.undefined expect(doPause.events.Paused).not.to.be.undefined - expect(doPause.events.Paused.address).to.equals(nonFungibleTokenAddress) + expect(doPause.events.Paused.address).to.equals(kip17Address) expect(await token.paused()).to.be.true @@ -1310,14 +1320,14 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-115: should send transaction for pausing with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const doPause = await token.pause({ from: sender.address }) expect(doPause.from).to.be.equals(sender.address.toLowerCase()) expect(doPause.status).to.be.true expect(doPause.events).not.to.be.undefined expect(doPause.events.Paused).not.to.be.undefined - expect(doPause.events.Paused.address).to.equals(nonFungibleTokenAddress) + expect(doPause.events.Paused.address).to.equals(kip17Address) expect(await token.paused()).to.be.true @@ -1327,7 +1337,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-116: should send transaction for pausing with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const customGasLimit = '0x30d40' const doPause = await token.pause({ from: sender.address, gas: customGasLimit }) @@ -1336,7 +1346,7 @@ describe('KIP17 token contract class test', () => { expect(doPause.status).to.be.true expect(doPause.events).not.to.be.undefined expect(doPause.events.Paused).not.to.be.undefined - expect(doPause.events.Paused.address).to.equals(nonFungibleTokenAddress) + expect(doPause.events.Paused.address).to.equals(kip17Address) expect(await token.paused()).to.be.true @@ -1346,7 +1356,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-117: should send transaction for pausing with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) // set deafult from address in kip17 instance token.options.from = sender.address @@ -1357,7 +1367,7 @@ describe('KIP17 token contract class test', () => { expect(doPause.status).to.be.true expect(doPause.events).not.to.be.undefined expect(doPause.events.Paused).not.to.be.undefined - expect(doPause.events.Paused.address).to.equals(nonFungibleTokenAddress) + expect(doPause.events.Paused.address).to.equals(kip17Address) expect(await token.paused()).to.be.true @@ -1369,7 +1379,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.unpause', () => { it('CAVERJS-UNIT-KCT-118: should send transaction for unpausing without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.pause({ from: sender.address }) @@ -1381,7 +1391,7 @@ describe('KIP17 token contract class test', () => { expect(doUnpause.status).to.be.true expect(doUnpause.events).not.to.be.undefined expect(doUnpause.events.Unpaused).not.to.be.undefined - expect(doUnpause.events.Unpaused.address).to.equals(nonFungibleTokenAddress) + expect(doUnpause.events.Unpaused.address).to.equals(kip17Address) expect(await token.paused()).to.be.false } @@ -1389,7 +1399,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-119: should send transaction for unpausing with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.pause({ from: sender.address }) @@ -1398,7 +1408,7 @@ describe('KIP17 token contract class test', () => { expect(doUnpause.status).to.be.true expect(doUnpause.events).not.to.be.undefined expect(doUnpause.events.Unpaused).not.to.be.undefined - expect(doUnpause.events.Unpaused.address).to.equals(nonFungibleTokenAddress) + expect(doUnpause.events.Unpaused.address).to.equals(kip17Address) expect(await token.paused()).to.be.false } @@ -1406,7 +1416,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-120: should send transaction for unpausing with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.pause({ from: sender.address }) @@ -1417,7 +1427,7 @@ describe('KIP17 token contract class test', () => { expect(doUnpause.status).to.be.true expect(doUnpause.events).not.to.be.undefined expect(doUnpause.events.Unpaused).not.to.be.undefined - expect(doUnpause.events.Unpaused.address).to.equals(nonFungibleTokenAddress) + expect(doUnpause.events.Unpaused.address).to.equals(kip17Address) expect(await token.paused()).to.be.false } @@ -1425,7 +1435,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-121: should send transaction for unpausing with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.pause({ from: sender.address }) @@ -1438,7 +1448,7 @@ describe('KIP17 token contract class test', () => { expect(doUnpause.status).to.be.true expect(doUnpause.events).not.to.be.undefined expect(doUnpause.events.Unpaused).not.to.be.undefined - expect(doUnpause.events.Unpaused.address).to.equals(nonFungibleTokenAddress) + expect(doUnpause.events.Unpaused.address).to.equals(kip17Address) expect(await token.paused()).to.be.false } @@ -1448,7 +1458,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.addPauser', () => { it('CAVERJS-UNIT-KCT-122: should send transaction for adding pauser and trigger PauserAdded event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const newPauser = caver.klay.accounts.create().address expect(await token.isPauser(newPauser)).to.be.false @@ -1461,7 +1471,7 @@ describe('KIP17 token contract class test', () => { expect(pauserAdded.status).to.be.true expect(pauserAdded.events).not.to.be.undefined expect(pauserAdded.events.PauserAdded).not.to.be.undefined - expect(pauserAdded.events.PauserAdded.address).to.equals(nonFungibleTokenAddress) + expect(pauserAdded.events.PauserAdded.address).to.equals(kip17Address) expect(await token.isPauser(newPauser)).to.be.true } @@ -1469,7 +1479,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-123: should send transaction for adding pauser and trigger PauserAdded event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const newPauser = caver.klay.accounts.create().address expect(await token.isPauser(newPauser)).to.be.false @@ -1479,7 +1489,7 @@ describe('KIP17 token contract class test', () => { expect(pauserAdded.status).to.be.true expect(pauserAdded.events).not.to.be.undefined expect(pauserAdded.events.PauserAdded).not.to.be.undefined - expect(pauserAdded.events.PauserAdded.address).to.equals(nonFungibleTokenAddress) + expect(pauserAdded.events.PauserAdded.address).to.equals(kip17Address) expect(await token.isPauser(newPauser)).to.be.true } @@ -1487,7 +1497,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-124: should send transaction for adding pauser and trigger PauserAdded event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const newPauser = caver.klay.accounts.create().address expect(await token.isPauser(newPauser)).to.be.false @@ -1499,7 +1509,7 @@ describe('KIP17 token contract class test', () => { expect(pauserAdded.status).to.be.true expect(pauserAdded.events).not.to.be.undefined expect(pauserAdded.events.PauserAdded).not.to.be.undefined - expect(pauserAdded.events.PauserAdded.address).to.equals(nonFungibleTokenAddress) + expect(pauserAdded.events.PauserAdded.address).to.equals(kip17Address) expect(await token.isPauser(newPauser)).to.be.true } @@ -1507,7 +1517,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-125: should send transaction for adding pauser and trigger PauserAdded event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const newPauser = caver.klay.accounts.create().address expect(await token.isPauser(newPauser)).to.be.false @@ -1521,7 +1531,7 @@ describe('KIP17 token contract class test', () => { expect(pauserAdded.status).to.be.true expect(pauserAdded.events).not.to.be.undefined expect(pauserAdded.events.PauserAdded).not.to.be.undefined - expect(pauserAdded.events.PauserAdded.address).to.equals(nonFungibleTokenAddress) + expect(pauserAdded.events.PauserAdded.address).to.equals(kip17Address) expect(await token.isPauser(newPauser)).to.be.true } @@ -1531,7 +1541,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.renouncePauser', () => { it('CAVERJS-UNIT-KCT-126: should send transaction for removing pauser and trigger PauserRemoved event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.addPauser(testAccount.address, { from: sender.address }) expect(await token.isPauser(testAccount.address)).to.be.true @@ -1544,7 +1554,7 @@ describe('KIP17 token contract class test', () => { expect(pauserRemoved.status).to.be.true expect(pauserRemoved.events).not.to.be.undefined expect(pauserRemoved.events.PauserRemoved).not.to.be.undefined - expect(pauserRemoved.events.PauserRemoved.address).to.equals(nonFungibleTokenAddress) + expect(pauserRemoved.events.PauserRemoved.address).to.equals(kip17Address) expect(await token.isPauser(testAccount.address)).to.be.false } @@ -1552,7 +1562,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-127: should send transaction for removing pauser and trigger PauserRemoved event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.addPauser(testAccount.address, { from: sender.address }) expect(await token.isPauser(testAccount.address)).to.be.true @@ -1562,7 +1572,7 @@ describe('KIP17 token contract class test', () => { expect(pauserRemoved.status).to.be.true expect(pauserRemoved.events).not.to.be.undefined expect(pauserRemoved.events.PauserRemoved).not.to.be.undefined - expect(pauserRemoved.events.PauserRemoved.address).to.equals(nonFungibleTokenAddress) + expect(pauserRemoved.events.PauserRemoved.address).to.equals(kip17Address) expect(await token.isPauser(testAccount.address)).to.be.false } @@ -1570,7 +1580,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-128: should send transaction for removing pauser and trigger PauserRemoved event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.addPauser(testAccount.address, { from: sender.address }) expect(await token.isPauser(testAccount.address)).to.be.true @@ -1582,7 +1592,7 @@ describe('KIP17 token contract class test', () => { expect(pauserRemoved.status).to.be.true expect(pauserRemoved.events).not.to.be.undefined expect(pauserRemoved.events.PauserRemoved).not.to.be.undefined - expect(pauserRemoved.events.PauserRemoved.address).to.equals(nonFungibleTokenAddress) + expect(pauserRemoved.events.PauserRemoved.address).to.equals(kip17Address) expect(await token.isPauser(testAccount.address)).to.be.false } @@ -1590,7 +1600,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-129: should send transaction for removing pauser and trigger PauserRemoved event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) await token.addPauser(testAccount.address, { from: sender.address }) expect(await token.isPauser(testAccount.address)).to.be.true @@ -1604,7 +1614,7 @@ describe('KIP17 token contract class test', () => { expect(pauserRemoved.status).to.be.true expect(pauserRemoved.events).not.to.be.undefined expect(pauserRemoved.events.PauserRemoved).not.to.be.undefined - expect(pauserRemoved.events.PauserRemoved.address).to.equals(nonFungibleTokenAddress) + expect(pauserRemoved.events.PauserRemoved.address).to.equals(kip17Address) expect(await token.isPauser(testAccount.address)).to.be.false } @@ -1614,7 +1624,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.supportsInterface', () => { it('CAVERJS-UNIT-KCT-138: should return true if interfaceId is supported', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) expect(await token.supportsInterface('0x80ac58cd')).to.be.true // kip17 expect(await token.supportsInterface('0x780e9d63')).to.be.true // kip17Enumerable @@ -1634,7 +1644,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.mint', () => { it('CAVERJS-UNIT-KCT-140: should send transaction for minting and trigger Transfer event without sendParams', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const originalSupply = await token.totalSupply() @@ -1646,7 +1656,7 @@ describe('KIP17 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.Transfer).not.to.be.undefined - expect(minted.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(minted.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenId) expect(owner.toLowerCase()).to.equals(testAccount.address.toLowerCase()) @@ -1660,7 +1670,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-141: should send transaction for minting and trigger Transfer event with sendParams(from)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const originalSupply = await token.totalSupply() @@ -1669,7 +1679,7 @@ describe('KIP17 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.Transfer).not.to.be.undefined - expect(minted.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(minted.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenId) expect(owner.toLowerCase()).to.equals(testAccount.address.toLowerCase()) @@ -1683,7 +1693,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-142: should send transaction for minting and trigger Transfer event with sendParams(from, gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const originalSupply = await token.totalSupply() @@ -1697,7 +1707,7 @@ describe('KIP17 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.Transfer).not.to.be.undefined - expect(minted.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(minted.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenId) expect(owner.toLowerCase()).to.equals(testAccount.address.toLowerCase()) @@ -1711,7 +1721,7 @@ describe('KIP17 token contract class test', () => { it('CAVERJS-UNIT-KCT-143: should send transaction for minting and trigger Transfer event with sendParams(gas)', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) const originalSupply = await token.totalSupply() @@ -1724,7 +1734,7 @@ describe('KIP17 token contract class test', () => { expect(minted.status).to.be.true expect(minted.events).not.to.be.undefined expect(minted.events.Transfer).not.to.be.undefined - expect(minted.events.Transfer.address).to.equals(nonFungibleTokenAddress) + expect(minted.events.Transfer.address).to.equals(kip17Address) const owner = await token.ownerOf(tokenId) expect(owner.toLowerCase()).to.equals(testAccount.address.toLowerCase()) @@ -1740,7 +1750,7 @@ describe('KIP17 token contract class test', () => { context('KIP17.detectInterface', () => { it('CAVERJS-UNIT-KCT-207: should return valid object if contract is deployed by caver', async () => { for (const kip17 of kip17s) { - const token = new kip17(nonFungibleTokenAddress) + const token = new kip17(kip17Address) let detected = await token.detectInterface() expect(detected.IKIP17).to.be.true @@ -1752,7 +1762,7 @@ describe('KIP17 token contract class test', () => { expect(detected.IKIP17Pausable).to.be.true // Test static function - detected = await kip17.detectInterface(nonFungibleTokenAddress) + detected = await kip17.detectInterface(kip17Address) expect(detected.IKIP17).to.be.true expect(detected.IKIP17Metadata).to.be.true @@ -1897,4 +1907,253 @@ describe('KIP17 token contract class test', () => { } }).timeout(200000) }) + + context('KIP17 with fee delegation', () => { + const contractDeployFormatter = receipt => { + return receipt + } + + it('CAVERJS-UNIT-KCT-233: should send TxTypeSmartContractDeploy to deploy when feeDelegation is defined as true', async () => { + const deployed = await caver.kct.kip17.deploy( + { + name: 'Jasmine', + symbol: 'JAS', + }, + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + contractDeployFormatter, + } + ) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.status).to.be.true + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-234: should send TxTypeFeeDelegatedSmartContractDeployWithRatio to deploy when feeRatio is defined and feeDelegation is defined as true', async () => { + const deployed = await caver.kct.kip17.deploy( + { + name: 'Jasmine', + symbol: 'JAS', + }, + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + feeRatio: 30, + contractDeployFormatter, + } + ) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.status).to.be.true + expect(deployed.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeployWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-235: should send TxTypeSmartContractExecution to add minter when feeDelegation is defined as true', async () => { + const token = caver.kct.kip17.create(kip17Address) + + const added = await token.addMinter(caver.wallet.keyring.generate().address, { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + }) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-236: should send TxTypeSmartContractExecution to add minter when feeDelegation is defined as true via options', async () => { + const token = caver.kct.kip17.create(kip17Address) + + token.options.from = sender.address + token.options.feeDelegation = true + token.options.feePayer = feePayer.address + + const added = await token.addMinter(caver.wallet.keyring.generate().address) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-237: should send TxTypeFeeDelegatedSmartContractExecutionWithRatio to add minter when feeRatio is defined and feeDelegation is defined as true', async () => { + const token = caver.kct.kip17.create(kip17Address) + + const added = await token.addMinter(caver.wallet.keyring.generate().address, { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + feeRatio: 30, + }) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecutionWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-238: should send TxTypeFeeDelegatedSmartContractExecutionWithRatio to add minter when feeRatio is defined and feeDelegation is defined as true via options', async () => { + const token = caver.kct.kip17.create(kip17Address) + + token.options.from = sender.address + token.options.feeDelegation = true + token.options.feePayer = feePayer.address + token.options.feeRatio = 30 + + const added = await token.addMinter(caver.wallet.keyring.generate().address) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecutionWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-239: should overwrite contract.options when user send sendOptions parameter', async () => { + const token = caver.kct.kip17.create(kip17Address) + + token.options.from = feePayer.address + token.options.feeDelegation = false + token.options.feePayer = sender.address + token.options.feeRatio = 50 + + const added = await token.addMinter(caver.wallet.keyring.generate().address, { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + feeRatio: 30, + gas: 1231234, + }) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(added.gas).to.equal(caver.utils.numberToHex(1231234)) + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecutionWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-240: should sign and return signed TxTypeFeeDelegatedSmartContractDeploy', async () => { + const token = caver.kct.kip17.create() + + const signed = await token.sign( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'constructor', + caver.kct.kip17.byteCode, + 'Jasmine', + 'JAS' + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.signatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + + await caver.wallet.signAsFeePayer(feePayer.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-241: should sign as fee payer and return signed TxTypeFeeDelegatedSmartContractDeploy', async () => { + const token = caver.kct.kip17.create() + + const signed = await token.signAsFeePayer( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'constructor', + caver.kct.kip17.byteCode, + 'Jasmine', + 'JAS' + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.feePayerSignatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + + await caver.wallet.sign(sender.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-242: should sign and return signed TxTypeFeeDelegatedSmartContractExecution', async () => { + const token = caver.kct.kip17.create(kip17Address) + + const signed = await token.sign( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'addMinter', + caver.wallet.keyring.generate().address + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.signatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + + await caver.wallet.signAsFeePayer(feePayer.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-243: should sign as fee payer and return signed TxTypeFeeDelegatedSmartContractExecution', async () => { + const token = caver.kct.kip17.create(kip17Address) + + const signed = await token.signAsFeePayer( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'addMinter', + caver.wallet.keyring.generate().address + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.feePayerSignatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + + await caver.wallet.sign(sender.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + }) }) diff --git a/test/packages/caver.klay.KIP7.js b/test/packages/caver.klay.KIP7.js index b922d045..f2e965ab 100644 --- a/test/packages/caver.klay.KIP7.js +++ b/test/packages/caver.klay.KIP7.js @@ -21,6 +21,7 @@ const BigNumber = require('bignumber.js') const testRPCURL = require('../testrpc') const { expect } = require('../extendedChai') +const { TX_TYPE_STRING } = require('../../packages/caver-transaction/src/transactionHelper/transactionHelper') const Caver = require('../../index.js') @@ -28,6 +29,7 @@ let caver let caver2 let kip7s let sender +let feePayer let testAccount let receiver @@ -75,6 +77,14 @@ before(function(done) { sender = caver.wallet.keyring.createFromPrivateKey(senderPrvKey) caver.wallet.add(sender) + const feePayerPrvKey = + process.env.privateKey2 && String(process.env.privateKey2).indexOf('0x') === -1 + ? `0x${process.env.privateKey2}` + : process.env.privateKey2 + + feePayer = caver.wallet.keyring.createFromPrivateKey(feePayerPrvKey) + caver.wallet.add(feePayer) + caver2.klay.accounts.wallet.add(senderPrvKey) kip7s = [caver.kct.kip7, caver2.klay.KIP7] @@ -2026,4 +2036,261 @@ describe(`KIP7 token contract class test`, () => { } }).timeout(200000) }) + + context('KIP7 with fee delegation', () => { + const contractDeployFormatter = receipt => { + return receipt + } + + it('CAVERJS-UNIT-KCT-222: should send TxTypeSmartContractDeploy to deploy when feeDelegation is defined as true', async () => { + const deployed = await caver.kct.kip7.deploy( + { + name: 'Jasmine', + symbol: 'JAS', + decimals: 18, + initialSupply: '10000000000000000000', + }, + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + contractDeployFormatter, + } + ) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.status).to.be.true + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-223: should send TxTypeFeeDelegatedSmartContractDeployWithRatio to deploy when feeRatio is defined and feeDelegation is defined as true', async () => { + const deployed = await caver.kct.kip7.deploy( + { + name: 'Jasmine', + symbol: 'JAS', + decimals: 18, + initialSupply: '10000000000000000000', + }, + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + feeRatio: 30, + contractDeployFormatter, + } + ) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.status).to.be.true + expect(deployed.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeployWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-224: should send TxTypeSmartContractExecution to add minter when feeDelegation is defined as true', async () => { + const token = caver.kct.kip7.create(kip7Address) + + const added = await token.addMinter(caver.wallet.keyring.generate().address, { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + }) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-225: should send TxTypeSmartContractExecution to add minter when feeDelegation is defined as true via options', async () => { + const token = caver.kct.kip7.create(kip7Address) + + token.options.from = sender.address + token.options.feeDelegation = true + token.options.feePayer = feePayer.address + + const added = await token.addMinter(caver.wallet.keyring.generate().address) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-226: should send TxTypeFeeDelegatedSmartContractExecutionWithRatio to add minter when feeRatio is defined and feeDelegation is defined as true', async () => { + const token = caver.kct.kip7.create(kip7Address) + + const added = await token.addMinter(caver.wallet.keyring.generate().address, { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + feeRatio: 30, + }) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecutionWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-227: should send TxTypeFeeDelegatedSmartContractExecutionWithRatio to add minter when feeRatio is defined and feeDelegation is defined as true via options', async () => { + const token = caver.kct.kip7.create(kip7Address) + + token.options.from = sender.address + token.options.feeDelegation = true + token.options.feePayer = feePayer.address + token.options.feeRatio = 30 + + const added = await token.addMinter(caver.wallet.keyring.generate().address) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecutionWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-228: should overwrite contract.options when user send sendOptions parameter', async () => { + const token = caver.kct.kip7.create(kip7Address) + + token.options.from = feePayer.address + token.options.feeDelegation = false + token.options.feePayer = sender.address + token.options.feeRatio = 50 + + const added = await token.addMinter(caver.wallet.keyring.generate().address, { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + feeRatio: 30, + gas: 1231234, + }) + + expect(added.from).to.equals(sender.address.toLowerCase()) + expect(added.status).to.be.true + expect(added.feeRatio).to.equal(caver.utils.numberToHex(30)) + expect(added.gas).to.equal(caver.utils.numberToHex(1231234)) + expect(added.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecutionWithRatio) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-229: should sign and return signed TxTypeFeeDelegatedSmartContractDeploy', async () => { + const token = caver.kct.kip7.create() + + const signed = await token.sign( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'constructor', + caver.kct.kip7.byteCode, + 'Jasmine', + 'JAS', + 18, + '10000000000000000000' + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.signatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + + await caver.wallet.signAsFeePayer(feePayer.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-230: should sign as fee payer and return signed TxTypeFeeDelegatedSmartContractDeploy', async () => { + const token = caver.kct.kip7.create() + + const signed = await token.signAsFeePayer( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'constructor', + caver.kct.kip7.byteCode, + 'Jasmine', + 'JAS', + 18, + '10000000000000000000' + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.feePayerSignatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + + await caver.wallet.sign(sender.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractDeploy) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-231: should sign and return signed TxTypeFeeDelegatedSmartContractExecution', async () => { + const token = caver.kct.kip7.create(kip7Address) + + const signed = await token.sign( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'addMinter', + caver.wallet.keyring.generate().address + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.signatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + + await caver.wallet.signAsFeePayer(feePayer.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + + it('CAVERJS-UNIT-KCT-232: should sign as fee payer and return signed TxTypeFeeDelegatedSmartContractExecution', async () => { + const token = caver.kct.kip7.create(kip7Address) + + const signed = await token.signAsFeePayer( + { + from: sender.address, + feeDelegation: true, + feePayer: feePayer.address, + gas: 30000000, + }, + 'addMinter', + caver.wallet.keyring.generate().address + ) + + expect(signed.from).to.equal(sender.address) + expect(signed.feePayer).to.equal(feePayer.address) + expect(caver.utils.isEmptySig(signed.feePayerSignatures)).to.be.false + expect(signed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + + await caver.wallet.sign(sender.address, signed) + + const deployed = await caver.rpc.klay.sendRawTransaction(signed) + + expect(deployed.from).to.equals(sender.address.toLowerCase()) + expect(deployed.feePayer).to.equals(feePayer.address.toLowerCase()) + expect(deployed.status).to.equal('0x1') + expect(deployed.type).to.equal(TX_TYPE_STRING.TxTypeFeeDelegatedSmartContractExecution) + }).timeout(200000) + }) })