diff --git a/shared_model/packages/javascript/package.json b/shared_model/packages/javascript/package.json index f2cd435c3f..a057a74fcf 100644 --- a/shared_model/packages/javascript/package.json +++ b/shared_model/packages/javascript/package.json @@ -7,7 +7,7 @@ "prepare": "sh scripts/generate-protobuf.sh", "prepublishOnly": "npm ls", "install": "node-pre-gyp install --fallback-to-build", - "test": "echo \"Error: no test specified\" && exit 1", + "test": "tape tests/**/*.js | tap-spec", "build": "node-pre-gyp build", "rebuild": "node-pre-gyp rebuild" }, @@ -50,7 +50,8 @@ "grpc-tools": "^1.6.6", "node-gyp": "^3.6.2", "node-pre-gyp-github": "^1.3.1", - "standard": "^11.0.1" + "tap-spec": "^4.1.1", + "tape": "^4.9.0" }, "bundledDependencies": [ "node-pre-gyp" diff --git a/shared_model/packages/javascript/tests/crypto.js b/shared_model/packages/javascript/tests/crypto.js new file mode 100644 index 0000000000..3832d3d606 --- /dev/null +++ b/shared_model/packages/javascript/tests/crypto.js @@ -0,0 +1,29 @@ +var test = require('tape') +var iroha = require('../index') + +const publicKey = '407e57f50ca48969b08ba948171bb2435e035d82cec417e18e4a38f5fb113f83' +const privateKey = '1d7e0a32ee0affeb4d22acd73c2c6fb6bd58e266c8c2ce4fa0ffe3dd6a253ffb' +const randomKey = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +const incorrectInputLength = 'aaaaaaaaaaaaaaaa' + +test('ModelCrypto tests', function (t) { + t.plan(8) + + let crypto = new iroha.ModelCrypto() + + t.throws(() => crypto.convertFromExisting(randomKey, randomKey), /Provided keypair is not correct/, 'Should throw "Provided keypair is not correct"') + t.throws(() => crypto.convertFromExisting(incorrectInputLength, incorrectInputLength), /input string has incorrect length/, 'Should throw "input string has incorrect length"') + + let keypair = crypto.convertFromExisting(publicKey, privateKey) + t.equal(keypair.publicKey().hex(), publicKey, 'Should be the same as public key was passed to convertFromExisting') + t.equal(keypair.privateKey().hex(), privateKey, 'Should be the same as private key was passed to convertFromExisting') + + let newKeypair = crypto.generateKeypair() + t.equal(newKeypair.publicKey().hex().length, publicKey.length, 'Size of generated public key should be the same as size of predefined public key') + t.equal(newKeypair.privateKey().hex().length, privateKey.length, 'Size of generated private key should be the same as size of predefined private key') + + t.throws(() => crypto.fromPrivateKey(incorrectInputLength), /input string has incorrect length/, 'Should throw "input string has incorrect length"') + t.equal(crypto.fromPrivateKey(privateKey).publicKey().hex(), publicKey) + + t.end() +}) diff --git a/shared_model/packages/javascript/tests/queryBuilder.js b/shared_model/packages/javascript/tests/queryBuilder.js new file mode 100644 index 0000000000..6a5ea1a2dd --- /dev/null +++ b/shared_model/packages/javascript/tests/queryBuilder.js @@ -0,0 +1,102 @@ +var test = require('tape') +var iroha = require('../index') + +const accountId = 'admin@test' +const assetId = 'coin#test' + +test('ModelQueryBuilder tests', function (t) { + t.plan(49) + + let queryBuilder = new iroha.ModelQueryBuilder() + const time = (new Date()).getTime() + + // Tests for concrete query + t.comment('Basic QueryBuilder tests') + t.throws(() => queryBuilder.build(), /Missing concrete query/, 'Should throw Missing concrete query') + t.throws(() => queryBuilder.creatorAccountId(accountId).build(), /Missing concrete query/, 'Should throw Missing concrete query') + t.throws(() => queryBuilder.creatorAccountId(accountId).createdTime(time).build(), /Missing concrete query/, 'Should throw Missing concrete query') + t.throws(() => queryBuilder.creatorAccountId(accountId).createdTime(time).queryCounter(1).build(), /Missing concrete query/, 'Should throw Missing concrete query') + t.throws(() => queryBuilder.creatorAccountId('').createdTime(time).queryCounter(1).getAccount(accountId).build(), /Wrongly formed creator_account_id, passed value: ''/, 'Should throw Wrongly formed creator_account_id') + t.throws(() => queryBuilder.creatorAccountId(accountId).createdTime(0).queryCounter(1).getAccount(accountId).build(), /bad timestamp: too old, timestamp: 0, now:/, 'Should throw bad timestamp: too old') + t.throws(() => queryBuilder.creatorAccountId(accountId).createdTime(time).queryCounter(0).getAccount(accountId).build(), /Counter should be > 0, passed value: 0/, 'Should throw Counter should be > 0') + + // Query with valid queryCounter, creatorAccountId and createdTime + let correctQuery = queryBuilder.creatorAccountId(accountId).createdTime(time).queryCounter(1) + + // getAccount() tests + t.comment('Testing getAccount()') + t.throws(() => correctQuery.getAccount(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getAccount('').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctQuery.getAccount('@@@').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id,') + t.doesNotThrow(() => correctQuery.getAccount(accountId).build(), null, 'Should not throw any exceptions') + + // getSignatories() tests + t.comment('Testing getSignatories()') + t.throws(() => correctQuery.getSignatories(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getSignatories('').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctQuery.getSignatories('@@@').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id,') + t.doesNotThrow(() => correctQuery.getSignatories(accountId).build(), null, 'Should not throw any exceptions') + + // getAccountTransactions() tests + t.comment('Testing getAccountTransactions()') + t.throws(() => correctQuery.getAccountTransactions(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getAccountTransactions('').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctQuery.getAccountTransactions('@@@').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id,') + t.doesNotThrow(() => correctQuery.getAccountTransactions(accountId).build(), null, 'Should not throw any exceptions') + + // getAccountAssetTransactions() tests + t.comment('Testing getAccountAssetTransactions()') + t.throws(() => correctQuery.getAccountAssetTransactions(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getAccountAssetTransactions(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getAccountAssetTransactions('', assetId).build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctQuery.getAccountAssetTransactions('@@@', assetId).build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctQuery.getAccountAssetTransactions(accountId, '').build(), /Wrongly formed asset_id, passed value: ''/, 'Should throw Wrongly formed asset_id,') + t.throws(() => correctQuery.getAccountAssetTransactions(accountId, '@@@').build(), /Wrongly formed asset_id, passed value: '@@@'/, 'Should throw Wrongly formed asset_id,') + t.doesNotThrow(() => correctQuery.getAccountAssetTransactions(accountId, assetId).build(), null, 'Should not throw any exceptions') + + // getAccountAssets() tests + t.comment('Testing getAccountAssets()') + t.throws(() => correctQuery.getAccountAssets(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getAccountAssets(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getAccountAssets('', assetId).build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctQuery.getAccountAssets('@@@', assetId).build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctQuery.getAccountAssets(accountId, '').build(), /Wrongly formed asset_id, passed value: ''/, 'Should throw Wrongly formed asset_id,') + t.throws(() => correctQuery.getAccountAssets(accountId, '@@@').build(), /Wrongly formed asset_id, passed value: '@@@'/, 'Should throw Wrongly formed asset_id,') + t.doesNotThrow(() => correctQuery.getAccountAssets(accountId, assetId).build(), null, 'Should not throw any exceptions') + + // getRoles() tests + t.comment('Testing getRoles()') + t.doesNotThrow(() => correctQuery.getRoles().build(), null, 'Should not throw any exceptions') + + // getAssetInfo() tests + t.comment('Testing getAssetInfo()') + t.throws(() => correctQuery.getAssetInfo(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getAssetInfo('').build(), /Wrongly formed asset_id, passed value: ''/, 'Should throw Wrongly formed asset_id,') + t.throws(() => correctQuery.getAssetInfo('@@@').build(), /Wrongly formed asset_id, passed value: '@@@'/, 'Should throw Wrongly formed asset_id,') + t.doesNotThrow(() => correctQuery.getAssetInfo(assetId).build(), null, 'Should not throw any exceptions') + + // getRolePermissions() tests + t.comment('Testing getRolePermissions()') + t.throws(() => correctQuery.getRolePermissions(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getRolePermissions('').build(), /Wrongly formed role_id, passed value: ''/, 'Should throw Wrongly formed role_id,') + t.throws(() => correctQuery.getRolePermissions('@@@').build(), /Wrongly formed role_id, passed value: '@@@'/, 'Should throw Wrongly formed role_id,') + t.doesNotThrow(() => correctQuery.getRolePermissions('role').build(), null, 'Should not throw any exceptions') + + // getTransactions() tests + t.comment('Testing getTransactions()') + t.throws(() => correctQuery.getTransactions(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getTransactions(''), /argument 2 of type 'std::vector< shared_model::crypto::Hash >/, 'Should throw ...argument 2 of type...') + let hv = new iroha.HashVector() + hv.add(new iroha.Hash('11111111111111111111111111111111')) + hv.add(new iroha.Hash('22222222222222222222222222222222')) + t.doesNotThrow(() => correctQuery.getTransactions(hv), null, 'Should not throw any exceptions') + + // getAccountDetail() tests + t.comment('Testing getAccountDetail()') + t.throws(() => correctQuery.getAccountDetail(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctQuery.getAccountDetail('').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctQuery.getAccountDetail('@@@').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id,') + t.doesNotThrow(() => correctQuery.getAccountDetail(accountId).build(), null, 'Should not throw any exceptions') + + t.end() +}) diff --git a/shared_model/packages/javascript/tests/txbuilder.js b/shared_model/packages/javascript/tests/txbuilder.js new file mode 100644 index 0000000000..79b59516ea --- /dev/null +++ b/shared_model/packages/javascript/tests/txbuilder.js @@ -0,0 +1,216 @@ +var test = require('tape') +var iroha = require('../index') + +const publicKey = '407e57f50ca48969b08ba948171bb2435e035d82cec417e18e4a38f5fb113f83' +const privateKey = '1d7e0a32ee0affeb4d22acd73c2c6fb6bd58e266c8c2ce4fa0ffe3dd6a253ffb' + +const adminAccountId = 'admin@test' +const assetId = 'coin#test' +const testAccountId = 'test@test' + +test('ModelTransactionBuilder tests', function (t) { + t.plan(130) + + let crypto = new iroha.ModelCrypto() + let keypair = crypto.convertFromExisting(publicKey, privateKey) + + let txBuilder = new iroha.ModelTransactionBuilder() + const time = (new Date()).getTime() + const address = '0.0.0.0:50051' + + t.comment('Basic TransactionBuilder tests') + + t.throws(() => txBuilder.build(), /Transaction should contain at least one command/, 'Should throw exception 0 commands in transaction, wrong creator_account_id, timestamp and counter') + t.throws(() => txBuilder.creatorAccountId(adminAccountId).build(), /Transaction should contain at least one command/, 'Should throw exception about zero commands in transaction, wrong timestamp and counter') + t.throws(() => txBuilder.creatorAccountId(adminAccountId).createdTime(0).txCounter(1).build(), /Transaction should contain at least one command bad timestamp: too old/, 'Should throw 0 commands + bad timestamp: too old') + t.throws(() => txBuilder.creatorAccountId(adminAccountId).createdTime(time).txCounter(0).build(), /Transaction should contain at least one command Counter should be > 0/, 'Should throw 0 commands + Counter should be > 0') + t.throws(() => txBuilder.creatorAccountId('').createdTime(time).txCounter(1).build(), /Transaction should contain at least one command Wrongly formed creator_account_id, passed value: ''/, 'Should throw 0 commands + Wrongly formed creator_account_id') + t.throws(() => txBuilder.creatorAccountId('@@@').createdTime(time).txCounter(1).build(), /Transaction should contain at least one command Wrongly formed creator_account_id, passed value: '@@@'/, 'Should throw 0 commands + Wrongly formed creator_account_id') + t.throws(() => txBuilder.creatorAccountId(adminAccountId).createdTime(time).txCounter(1).build(), /Transaction should contain at least one command/, 'Should throw exception about zero commands in transaction') + + // Transaction with valid txCounter, creatorAccountId and createdTime + let correctTx = txBuilder.creatorAccountId(adminAccountId).createdTime(time).txCounter(1) + + // addAssetQuantity() tests + t.comment('Testing addAssetQuantity()') + t.throws(() => correctTx.addAssetQuantity(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.addAssetQuantity(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.addAssetQuantity('', ''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.addAssetQuantity('', '', '').build(), /AddAssetQuantity: \[\[Wrongly formed account_id, passed value: '' Wrongly formed asset_id, passed value: '' Amount must be greater than 0, passed value: 0 \]\]/, 'Should throw wrongly formed account_id, asset_id, Amount must be greater than 0') + t.throws(() => correctTx.addAssetQuantity(adminAccountId, assetId, '0').build(), /AddAssetQuantity: \[\[Amount must be greater than 0, passed value: 0 \]\]/, 'Should throw Amount must be greater than 0') + t.throws(() => correctTx.addAssetQuantity('', assetId, '1000').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.addAssetQuantity('@@@', assetId, '1000').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.addAssetQuantity(adminAccountId, '', '1000').build(), /Wrongly formed asset_id, passed value: ''/, 'Should throw Wrongly formed asset_id') + t.throws(() => correctTx.addAssetQuantity(adminAccountId, '###', '1000').build(), /Wrongly formed asset_id, passed value: '###'/, 'Should throw Wrongly formed asset_id') + t.doesNotThrow(() => correctTx.addAssetQuantity(adminAccountId, assetId, '1000').build(), null, 'Should not throw any exceptions') + + // addPeer() tests + t.comment('Testing addPeer()') + t.throws(() => correctTx.addPeer(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.addPeer(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.addPeer('', keypair.publicKey()).build(), /Wrongly formed peer address/, 'Should throw exception about wrongly formed peer address') + t.throws(() => correctTx.addPeer(address, '').build(), /argument 3 of type 'shared_model::crypto::PublicKey const &'/, 'Should throw ...argument 3 of type...') + t.doesNotThrow(() => correctTx.addPeer(address, keypair.publicKey()).build(), null, 'Should not throw any exceptions') + + // addSignatory() tests + t.comment('Testing addSignatory()') + t.throws(() => correctTx.addSignatory(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.addSignatory(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.addSignatory('', keypair.publicKey()).build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.addSignatory('@@@', keypair.publicKey()).build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.addSignatory(adminAccountId, '').build(), /argument 3 of type 'shared_model::crypto::PublicKey const &'/, 'Should throw ...argument 3 of type...') + t.doesNotThrow(() => correctTx.addSignatory(adminAccountId, keypair.publicKey()).build(), null, 'Should not throw any exceptions') + + // removeSignatory() tests + t.comment('Testing removeSignatory()') + t.throws(() => correctTx.removeSignatory(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.removeSignatory(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.removeSignatory('', keypair.publicKey()).build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.removeSignatory('@@@', keypair.publicKey()).build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.removeSignatory(adminAccountId, '').build(), /argument 3 of type 'shared_model::crypto::PublicKey const &'/, 'Should throw ...argument 3 of type...') + t.doesNotThrow(() => correctTx.removeSignatory(adminAccountId, keypair.publicKey()).build(), null, 'Should not throw any exceptions') + + // appendRole() tests + t.comment('Testing appendRole()') + t.throws(() => correctTx.appendRole(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.appendRole(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.appendRole('', 'ruser').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.appendRole('@@@', 'ruser').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.appendRole(adminAccountId, '').build(), /Wrongly formed role_id, passed value: ''/, 'Should throw Wrongly formed role_id') + t.throws(() => correctTx.appendRole(adminAccountId, '@@@').build(), /Wrongly formed role_id, passed value: '@@@'/, 'Should throw Wrongly formed role_id') + // TODO: 8 symbols + t.doesNotThrow(() => correctTx.appendRole(adminAccountId, 'ruser').build(), null, 'Should not throw any exceptions') + + // createAsset() tests + t.comment('Testing createAsset()') + t.throws(() => correctTx.createAsset(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.createAsset(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.createAsset('', ''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.createAsset('', 'domain', 2).build(), /Wrongly formed asset_name, passed value: ''/, 'Should throw Wrongly formed asset_name') + t.throws(() => correctTx.createAsset('$$$', 'domain', 2).build(), /Wrongly formed asset_name, passed value: '\$\$\$'/, 'Should throw Wrongly formed asset_name') + t.throws(() => correctTx.createAsset('coin', '', 2).build(), /Wrongly formed domain_id, passed value: ''/, 'Should throw Wrongly formed domain_id') + t.throws(() => correctTx.createAsset('coin', '$$$', 2).build(), /Wrongly formed domain_id, passed value: '\$\$\$'/, 'Should throw Wrongly formed domain_id') + t.throws(() => correctTx.createAsset('coin', 'domain', -10).build(), /argument 4 of type 'shared_model::interface::types::PrecisionType'/, 'Should throw ...argument 4 of type...') + // t.throws(() => correctTx.createAsset('coin', 'domain', 1.2).build(), /argument 4 of type 'shared_model::interface::types::PrecisionType'/, 'Should throw ...argument 4 of type...') + t.doesNotThrow(() => correctTx.createAsset('coin', 'domain', 2).build(), null, 'Should not throw any exceptions') + + // createAccount() tests + t.comment('Testing createAccount()') + t.throws(() => correctTx.createAccount(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.createAccount(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.createAccount('', ''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.createAccount('', 'domain', keypair.publicKey()).build(), /Wrongly formed account_name, passed value: ''/, 'Should throw Wrongly formed asset_name') + t.throws(() => correctTx.createAccount('$$$', 'domain', keypair.publicKey()).build(), /Wrongly formed account_name, passed value: '\$\$\$'/, 'Should throw Wrongly formed asset_name') + t.throws(() => correctTx.createAccount('admin', '', keypair.publicKey()).build(), /Wrongly formed domain_id, passed value: ''/, 'Should throw Wrongly formed domain_id') + t.throws(() => correctTx.createAccount('admin', '$$$', keypair.publicKey()).build(), /Wrongly formed domain_id, passed value: '\$\$\$'/, 'Should throw Wrongly formed domain_id') + t.throws(() => correctTx.createAccount('admin', 'domain', 'aaa'), /argument 4 of type 'shared_model::crypto::PublicKey/, 'Should throw ...argument 4 of type...') + t.doesNotThrow(() => correctTx.createAccount('admin', 'domain', keypair.publicKey()).build(), null, 'Should not throw any exceptions') + + // createDomain() tests + t.comment('Testing createDomain()') + t.throws(() => correctTx.createDomain(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.createDomain(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.createDomain('', 'ruser').build(), /Wrongly formed domain_id, passed value: ''/, 'Should throw Wrongly formed domain_id') + t.throws(() => correctTx.createDomain('$$$', 'ruser').build(), /Wrongly formed domain_id, passed value: '\$\$\$'/, 'Should throw Wrongly formed domain_id') + t.throws(() => correctTx.createDomain('domain', '').build(), /Wrongly formed role_id, passed value: ''/, 'Should throw Wrongly formed role_id') + t.throws(() => correctTx.createDomain('domain', '@@@').build(), /Wrongly formed role_id, passed value: '@@@'/, 'Should throw Wrongly formed role_id') + t.doesNotThrow(() => correctTx.createDomain('domain', 'ruser').build(), null, 'Should not throw any exceptions') + + // createRole() tests + t.comment('Testing createRole()') + t.throws(() => correctTx.createRole(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.createRole(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + let sv = new iroha.StringVector() + sv.add('permission1') + sv.add('permission2') + t.throws(() => correctTx.createRole('', sv).build(), /Wrongly formed role_id, passed value: ''/, 'Should throw Wrongly formed role_id') + t.throws(() => correctTx.createRole('@@@', sv).build(), /Wrongly formed role_id, passed value: '@@@'/, 'Should throw Wrongly formed role_id') + t.throws(() => correctTx.createRole('ruser', '').build(), /argument 3 of type 'std::vector< shared_model::interface::types::PermissionNameType >/, 'Should throw ...argument 3 of type...') + t.doesNotThrow(() => correctTx.createRole('ruser', sv).build(), null, 'Should not throw any exceptions') + + // detachRole() tests + t.comment('Testing detachRole()') + t.throws(() => correctTx.detachRole(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.detachRole(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.detachRole('', 'ruser').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.detachRole('@@@', 'ruser').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.detachRole(adminAccountId, '').build(), /Wrongly formed role_id, passed value: ''/, 'Should throw Wrongly formed role_id') + t.throws(() => correctTx.detachRole(adminAccountId, '@@@').build(), /Wrongly formed role_id, passed value: '@@@'/, 'Should throw Wrongly formed role_id') + // TODO: 8 symbols + t.doesNotThrow(() => correctTx.detachRole(adminAccountId, 'ruser').build(), null, 'Should not throw any exceptions') + + // grantPermission() tests + t.comment('Testing grantPermission()') + t.throws(() => correctTx.grantPermission(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.grantPermission(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.grantPermission('', 'can_read_assets').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.grantPermission('@@@', 'can_read_assets').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.grantPermission(adminAccountId, '').build(), /Wrongly formed permission, passed value: ''/, 'Should throw Wrongly formed permission') + t.throws(() => correctTx.grantPermission(adminAccountId, '@@@').build(), /Wrongly formed permission, passed value: '@@@'/, 'Should throw Wrongly formed permission') + t.doesNotThrow(() => correctTx.grantPermission(adminAccountId, 'can_read_assets').build(), null, 'Should not throw any exceptions') + + // revokePermission() tests + t.comment('Testing revokePermission()') + t.throws(() => correctTx.revokePermission(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.revokePermission(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.revokePermission('', 'can_read_assets').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.revokePermission('@@@', 'can_read_assets').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.revokePermission(adminAccountId, '').build(), /Wrongly formed permission, passed value: ''/, 'Should throw Wrongly formed permission') + t.throws(() => correctTx.revokePermission(adminAccountId, '@@@').build(), /Wrongly formed permission, passed value: '@@@'/, 'Should throw Wrongly formed permission') + t.doesNotThrow(() => correctTx.revokePermission(adminAccountId, 'can_read_assets').build(), null, 'Should not throw any exceptions') + + // setAccountDetail() tests + t.comment('Testing setAccountDetail()') + t.throws(() => correctTx.setAccountDetail(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.setAccountDetail(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.setAccountDetail('', ''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.setAccountDetail('', 'key', 'value').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.setAccountDetail('@@@', 'key', 'value').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.setAccountDetail(adminAccountId, '', 'value').build(), /Wrongly formed key, passed value: ''/, 'Should throw Wrongly formed key') + t.throws(() => correctTx.setAccountDetail(adminAccountId, '@@@', 'value').build(), /Wrongly formed key, passed value: '@@@'/, 'Should throw Wrongly formed key') + t.doesNotThrow(() => correctTx.setAccountDetail(adminAccountId, 'key', 'value').build(), null, 'Should not throw any exceptions') + + // setAccountQuorum() tests + t.comment('Testing setAccountQuorum()') + t.throws(() => correctTx.setAccountQuorum(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.setAccountQuorum(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.setAccountQuorum('', 10).build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.setAccountQuorum('@@@', 10).build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.setAccountQuorum(adminAccountId, 'kek').build(), /argument 3 of type 'shared_model::interface::types::QuorumType'/, 'Should throw ...argument 3 of type...') + t.doesNotThrow(() => correctTx.setAccountQuorum(adminAccountId, 10).build(), null, 'Should not throw any exceptions') + + // subtractAssetQuantity() tests + t.comment('Testing subtractAssetQuantity()') + t.throws(() => correctTx.subtractAssetQuantity(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.subtractAssetQuantity(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.subtractAssetQuantity('', ''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.subtractAssetQuantity('', '', '').build(), /SubtractAssetQuantity: \[\[Wrongly formed account_id, passed value: '' Wrongly formed asset_id, passed value: '' Amount must be greater than 0, passed value: 0 \]\]/, 'Should throw wrongly formed account_id, asset_id, Amount must be greater than 0') + t.throws(() => correctTx.subtractAssetQuantity(adminAccountId, assetId, '0').build(), /SubtractAssetQuantity: \[\[Amount must be greater than 0, passed value: 0 \]\]/, 'Should throw Amount must be greater than 0') + // TODO: MAYBE Throw an exception on real amount + // t.throws(() => correctTx.subtractAssetQuantity(adminAccountId, assetId, '0.123').build(), /SubtractAssetQuantity: \[\[Amount must be integer, passed value: 0.123 \]\]/, 'Should throw Amount must be integer') + t.throws(() => correctTx.subtractAssetQuantity('', assetId, '1000').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.subtractAssetQuantity('@@@', assetId, '1000').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id') + t.throws(() => correctTx.subtractAssetQuantity(adminAccountId, '', '1000').build(), /Wrongly formed asset_id, passed value: ''/, 'Should throw Wrongly formed asset_id') + t.throws(() => correctTx.subtractAssetQuantity(adminAccountId, '###', '1000').build(), /Wrongly formed asset_id, passed value: '###'/, 'Should throw Wrongly formed asset_id') + t.doesNotThrow(() => correctTx.subtractAssetQuantity(adminAccountId, assetId, '1000').build(), null, 'Should not throw any exceptions') + + // transferAsset() tests + t.comment('Testing transferAsset()') + t.throws(() => correctTx.transferAsset(), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.transferAsset(''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.transferAsset('', ''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.transferAsset('', '', ''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.transferAsset('', '', '', ''), /Error: Illegal number of arguments/, 'Should throw Illegal number of arguments') + t.throws(() => correctTx.transferAsset('', testAccountId, assetId, 'some message', '100').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctTx.transferAsset('@@@', testAccountId, assetId, 'some message', '100').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctTx.transferAsset(adminAccountId, '', assetId, 'some message', '100').build(), /Wrongly formed account_id, passed value: ''/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctTx.transferAsset(adminAccountId, '@@@', assetId, 'some message', '100').build(), /Wrongly formed account_id, passed value: '@@@'/, 'Should throw Wrongly formed account_id,') + t.throws(() => correctTx.transferAsset(adminAccountId, testAccountId, '', 'some message', '100').build(), /Wrongly formed asset_id, passed value: ''/, 'Should throw Wrongly formed asset_id,') + t.throws(() => correctTx.transferAsset(adminAccountId, testAccountId, '@@@', 'some message', '100').build(), /Wrongly formed asset_id, passed value: '@@@'/, 'Should throw Wrongly formed asset_id,') + t.throws(() => correctTx.transferAsset(adminAccountId, testAccountId, assetId, 'some mesage', '0').build(), /TransferAsset: \[\[Amount must be greater than 0, passed value: 0 \]\]/, 'Should throw Amount must be greater than 0') + // TODO: MAYBE Throw an exception on real amount + // t.throws(() => correctTx.transferAsset(adminAccountId, testAccountId, assetId, 'some mesage', '0.123').build(), /TransferAsset: \[\[Amount must be integer, passed value: 0.123 \]\]/, 'Should throw Amount must be integer') + t.doesNotThrow(() => correctTx.transferAsset(adminAccountId, testAccountId, assetId, 'some mesage', '100').build(), null, 'Should not throw any exceptions') + + t.end() +})