diff --git a/lib/transactions/gateway.js b/lib/transactions/gateway.js index 82ade01..3655c35 100644 --- a/lib/transactions/gateway.js +++ b/lib/transactions/gateway.js @@ -1,14 +1,14 @@ var crypto = require("./crypto.js") var transaction = require('./transaction.js') -function registerMember(options, secret, secondSecret) { +function registerMember(gateway, memberPublicKey, secret, secondSecret) { let keys = crypto.getKeys(secret); return transaction.createTransactionEx({ type: 401, fee: 100 * 1e8, secret: secret, secondSecret, secondSecret, - args: [options.gateway, keys.publicKey] + args: [gateway, memberPublicKey] }) } diff --git a/lib/transactions/proposal.js b/lib/transactions/proposal.js index 6083a3c..fc43bd5 100644 --- a/lib/transactions/proposal.js +++ b/lib/transactions/proposal.js @@ -1,88 +1,125 @@ var crypto = require("./crypto.js") var transaction = require('./transaction.js') -/*function propose(options, secret, secondSecret) { - var keys = crypto.getKeys(secret); +function registerGateway(options, secret, secondSecret) { + // construct content + let content = { + name : options.gatewayName, + desc : options.gatewayDesc, + minimumMembers: options.minimumMembers || 3, + updateInterval: options.updateInterval || 8640, + currency: { + symbol : options.currencySymbol, + desc: options.currencyDesc, + precision : options.currencyPrecision + } + } + return transaction.createTransactionEx({ - type: 300, - fee: 10 * 1e8, - secret: secret, - secondSecret, secondSecret, - args: [options.title, options.desc, null, null, options.endHeight] + type: 300, + fee: 10 * 1e8, + secret: secret, + secondSecret: secondSecret, + args: [ + options.proposalTitle || 'title for gateway_register', + options.proposalDesc, 'gateway_register', + content, + options.proposalEndHeight + ] }) -}*/ +} -function registergateway(options, secret, secondSecret) { - - let keys = crypto.getKeys(secret); - let currency = { - symbol : options.symbol, - desc: options.currencyDesc, - precision : options.precision - } - // construct this content +function initGateway(options, secret, secondSecret) { + // construct content let content = { - name : options.name, - desc : options.desc, - minimumMembers: options.minimumMembers, - updateInterval: options.updateInterval, - currency: currency + gateway : options.gatewayName, + members: options.gatewayMembers } + return transaction.createTransactionEx({ type: 300, fee: 10 * 1e8, secret: secret, - secondSecret, secondSecret, - args: [options.title, options.desc, 'gateway_register', content, options.endHeight] + secondSecret: secondSecret, + args: [ + options.proposalTitle || 'title for gateway_init', + options.proposalDesc || 'desc for gateway_init', + 'gateway_init', + content, + options.proposalEndHeight + ] }) } -function initgateway(options, secret, secondSecret) { - - let keys = crypto.getKeys(secret); - // construct this content +function updateGatewayMember(options, secret, secondSecret) { + // construct content let content = { - gateway : options.name, - members: options.members + gateway: options.gatewayName, + from: options.fromAddress, + to: options.toAddress } return transaction.createTransactionEx({ type: 300, fee: 10 * 1e8, secret: secret, - secondSecret, secondSecret, - args: ['xxxxxxxxxx', '', 'gateway_init', content, 500000] + secondSecret: secondSecret, + args: [ + options.proposalTitle || 'title for gateway_update_member', + options.proposalDesc || 'desc for gateway_update_member', + 'gateway_update_member', + content, + options.proposalEndHeight + ] }) } -function activate(options, secret, secondSecret) { +function revokeGateway(options, secret, secondSecret) { + // construct content + let content = { + gateway: options.gatewayName + } + + return transaction.createTransactionEx({ + type: 300, + fee: 10 * 1e8, + secret: secret, + secondSecret: secondSecret, + args: [ + options.proposalTitle || 'title for gateway_revoke', + options.proposalDesc || 'desc for gateway_revoke', + 'gateway_revoke', + content, + options.proposalEndHeight + ] + }) +} - let keys = crypto.getKeys(secret); +function activateProposal(tid, secret, secondSecret) { return transaction.createTransactionEx({ type: 302, fee: 0 * 1e8, secret: secret, - secondSecret, secondSecret, - args: [options.tid] + secondSecret: secondSecret, + args: [tid] }) } -function upvote(options, secret, secondSecret) { - - let keys = crypto.getKeys(secret); +function upvoteProposal(tid, secret, secondSecret) { return transaction.createTransactionEx({ type: 301, fee: 1e7, // 0.1 * 1e8 secret: secret, - secondSecret, secondSecret, - args: [options.tid] + secondSecret: secondSecret, + args: [tid] }) } module.exports = { - //propose: propose - registergateway: registergateway, - initgateway: initgateway, - activate: activate, - upvote: upvote + registerGateway: registerGateway, + initGateway: initGateway, + updateGatewayMember: updateGatewayMember, + revokeGateway: revokeGateway, + activateProposal: activateProposal, + upvoteProposal: upvoteProposal } diff --git a/package.json b/package.json index b71a871..fb7fb1e 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "license": "MIT", "types": "./types/index.d.ts", "dependencies": { - "@types/node": "^10.9.4", + "@types/node": "=8.10.29", "JSONStream": "=1.3.1", "browserify-bignum": "=1.3.0-2", "buffer": "=4.7.0", diff --git a/test/gateway.js b/test/gateway.js new file mode 100644 index 0000000..12d6aa7 --- /dev/null +++ b/test/gateway.js @@ -0,0 +1,104 @@ +var Buffer = require("buffer/").Buffer; +var should = require("should"); +var asch = require("../index.js"); + +describe("gateway.js", () => { + var gateway = asch.gateway; + + it("should be ok", () => { + (gateway).should.be.ok; + }); + + it("should be object", () => { + (gateway).should.be.type("object"); + }); + + describe("#registerMember", () => { + var registerMember; + var trs; + + beforeEach(() => { + registerMember = asch.gateway.registerMember; + let publicKey = asch.crypto.getKeys("secret").publicKey; + trs = registerMember("name", publicKey, "secret"); + }); + + afterEach(() => { + trs = null; + }); + + it("should have property registerMember", () => { + (gateway).should.have.property("registerMember"); + }); + + it("should be function", () => { + (registerMember).should.be.type("function"); + }); + + it("should create registerMember transaction", () => { + (trs).should.be.ok; + (trs).should.be.type("object"); + }); + + describe("returned registerMember transaction", () => { + it("should have id as string", () => { + (trs.id).should.be.type("string"); + }); + + it("should have type as number and equal 401", () => { + (trs.type).should.be.type("number").and.equal(401); + }); + + it("should have args as array with 2 items", () => { + (trs.args).should.be.an.Array().with.a.lengthOf(2); + }); + + it("should have gateway-name as first item", () => { + should(trs.args[0]).be.type("string").and.equal("name"); + }); + + it("should have publicKey from new member as second item", () => { + should(trs.args[1]).be.type("string").and.equal("5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09"); + }); + + it("should have fee and equal 100 XAS", () => { + (trs.fee).should.be.type("number").and.equal(100 * 1e8); + }); + + it("should have senderPublicKey as hex string", () => { + (trs.senderPublicKey).should.be.type("string").and.match(function (given) { + try { + new Buffer(trs.senderPublicKey, "hex"); + } catch (e) { + return false; + } + + return true; + }); + }); + + it("should have one signature as hex string in signatures array", () => { + (trs.signatures[0]).should.be.type("string").and.match(() => { + try { + new Buffer(trs.signatures[0], "hex") + } catch (e) { + return false; + } + return true; + }) + }); + + it("should be signed correctly", () => { + var result = asch.crypto.verify(trs); + + (result).should.be.ok; + }); + + it("should not be signed correctly now", () => { + trs.amount = 24242424; + var result = asch.crypto.verify(trs); + (result).should.be.not.ok; + }); + }); + }); +}); diff --git a/test/proposal.js b/test/proposal.js new file mode 100644 index 0000000..e09e866 --- /dev/null +++ b/test/proposal.js @@ -0,0 +1,758 @@ +var Buffer = require("buffer/").Buffer; +var should = require("should"); +var asch = require("../index.js"); + +function cloneObject(obj) { + var clone = JSON.parse(JSON.stringify(obj)); + return clone; +} + +describe("proposal.js", () => { + var proposal = asch.proposal; + + it("should be ok", () => { + (proposal).should.be.ok; + }); + + it("should be object", () => { + (proposal).should.be.type("object"); + }); + + describe("#registerGateway", () => { + var registerGateway; + var options; + var trs; + + beforeEach(() => { + registerGateway = proposal.registerGateway; + options = { + gatewayName: "name", + gatewayDesc: "desc", + currencySymbol: "BTC", + currencyDesc: "Bitcoin currency", + currencyPrecision: 8, + proposalEndHeight: 20000 + }; + trs = registerGateway(options, "secret"); + }); + + afterEach(() => { + trs = null; + }); + + it("should have property registerGateway", () => { + (proposal).should.have.property("registerGateway"); + }); + + it("should be function", () => { + (registerGateway).should.be.type("function"); + }); + + it("should create registerGateway transaction", () => { + (trs).should.be.ok; + (trs).should.be.type("object"); + }); + + describe("returned registerGateway transaction", () => { + it("should have id as string", () => { + (trs.id).should.be.type("string"); + }); + + it("should have type as number and equal 300", () => { + (trs.type).should.be.type("number").and.equal(300); + }); + + it("should have args as array with 5 items", () => { + (trs.args).should.be.an.Array().with.a.lengthOf(5); + }); + + it("should have fee and equal 10 XAS", () => { + (trs.fee).should.be.type("number").and.equal(10 * 1e8); + }); + + it("should have senderPublicKey as hex string", () => { + (trs.senderPublicKey).should.be.type("string").and.match(function (given) { + try { + new Buffer(trs.senderPublicKey, "hex"); + } catch (e) { + return false; + } + + return true; + }); + }); + + it("should have one signature as hex string in signatures array", () => { + (trs.signatures[0]).should.be.type("string").and.match(() => { + try { + new Buffer(trs.signatures[0], "hex") + } catch (e) { + return false; + } + return true; + }) + }); + + it("should be signed correctly", () => { + var result = asch.crypto.verify(trs); + + (result).should.be.ok; + }); + + it("should not be signed correctly now", () => { + trs.amount = 2424; + var result = asch.crypto.verify(trs); + (result).should.be.not.ok; + }); + + describe("args", () => { + + it("should overwrite proposal title", () => { + let newOptions = cloneObject(options); + + let proposalTitle = "overwritten title"; + newOptions.proposalTitle = proposalTitle; + + let trs = registerGateway(newOptions, "secret"); + should(trs.args[0]).be.type("string").and.equal("overwritten title"); + }); + + it("should overwrite proposal description", () => { + let newOptions = cloneObject(options); + + let proposalDesc = "overwritten description"; + newOptions.proposalDesc = proposalDesc; + + let trs = registerGateway(newOptions, "secret"); + should(trs.args[1]).be.type("string").and.equal("overwritten description"); + }); + + it("should have proposal type gateway_register as 3rd item", () => { + should(trs.args[2]).equal("gateway_register"); + }); + + it("should set content.name", () => { + should(trs.args[3]).have.property("name").and.equal("name"); + }); + + it("should set content.desc", () => { + should(trs.args[3]).have.property("desc").and.equal("desc"); + }); + + it("should have default content.minimumMembers of 3", () => { + let newOptions = cloneObject(options); + + let trs = registerGateway(newOptions, "secret"); + should(trs.args[3]).have.property("minimumMembers").and.equal(3); + }); + + it("should overwrite content.minimumMembers", () => { + let newOptions = cloneObject(options); + + let newMinimumMembers = 5; + newOptions.minimumMembers = newMinimumMembers; + + let trs = registerGateway(newOptions, "secret"); + should(trs.args[3]).have.property("minimumMembers").and.equal(5); + }); + + it("should have default content.updateInterval of 8640", () => { + let newOptions = { + gatewayName: "name", + gatewayDesc: "desc", + currencySymbol: "BTC", + currencyDesc: "Bitcoin currency", + currencyPrecision: 8, + proposalEndHeight: 20000, + updateInterval: undefined + }; + + let trs = registerGateway(newOptions, "secret"); + should(trs.args[3]).have.property("updateInterval").and.equal(8640); + }); + + it("should overwrite content.updateInterval", () => { + let newOptions = cloneObject(options); + + let newUpdateInterval = 10000; + newOptions.updateInterval = newUpdateInterval; + + let trs = registerGateway(newOptions, "secret"); + + should(trs.args[3]).have.property("updateInterval").and.equal(10000); + }); + + it("should args have currency property of type object", () => { + should(trs.args[3]).have.property("currency").and.be.type("object"); + }); + + it("should set content.currency.symbol", () => { + should(trs.args[3].currency).have.property("symbol").and.be.type("string").and.equal("BTC"); + }); + + it("should set content.currency.desc", () => { + should(trs.args[3].currency).have.property("desc").and.be.type("string").and.equal("Bitcoin currency"); + }); + + it("should set content.currency.precision", () => { + should(trs.args[3].currency).have.property("precision").and.be.type("number").and.equal(8); + }); + + it("should set proposalEndheight", () => { + should(trs.args[4]).be.type("number").and.equal(20000); + }); + }); + }); + }); + + describe("#initGateway", () => { + var initGateway; + var options; + var trs; + + beforeEach(() => { + initGateway = proposal.initGateway; + options = { + gatewayName: 'name', + gatewayMembers: [ + "address1", + "address2", + "address3" + ], + proposalEndHeight: 25000 + } + trs = initGateway(options, "secret"); + }); + + afterEach(() => { + trs = null; + }); + + it("should have property initGateway", () => { + (proposal).should.have.property("initGateway"); + }); + + it("should be function", () => { + (initGateway).should.be.type("function"); + }); + + it("should create initGateway transaction", () => { + (trs).should.be.ok; + (trs).should.be.type("object"); + }); + + describe("returned initGateway transaction", () => { + it("should have id as string", () => { + (trs.id).should.be.type("string"); + }); + + it("should have type as number and equal 300", () => { + (trs.type).should.be.type("number").and.equal(300); + }); + + it("should have args as array with 5 items", () => { + (trs.args).should.be.an.Array().with.a.lengthOf(5); + }); + + it("should have fee and equal 10 XAS", () => { + (trs.fee).should.be.type("number").and.equal(10 * 1e8); + }); + + it("should have senderPublicKey as hex string", () => { + (trs.senderPublicKey).should.be.type("string").and.match(function (given) { + try { + new Buffer(trs.senderPublicKey, "hex"); + } catch (e) { + return false; + } + + return true; + }); + }); + + it("should have one signature as hex string in signatures array", () => { + (trs.signatures[0]).should.be.type("string").and.match(() => { + try { + new Buffer(trs.signatures[0], "hex") + } catch (e) { + return false; + } + return true; + }) + }); + + it("should be signed correctly", () => { + var result = asch.crypto.verify(trs); + + (result).should.be.ok; + }); + + it("should not be signed correctly now", () => { + trs.amount = 2525; + var result = asch.crypto.verify(trs); + (result).should.be.not.ok; + }); + + describe("args", () => { + it("should overwrite proposal title", () => { + let newOptions = cloneObject(options); + + let proposalTitle = "overwritten title"; + newOptions.proposalTitle = proposalTitle; + + let trs = initGateway(newOptions, "secret"); + should(trs.args[0]).be.type("string").and.equal("overwritten title"); + }); + + it("should overwrite proposal description", () => { + let newOptions = cloneObject(options); + + let proposalDesc = "overwritten description"; + newOptions.proposalDesc = proposalDesc; + + let trs = initGateway(newOptions, "secret"); + should(trs.args[1]).be.type("string").and.equal("overwritten description"); + }); + + it("should have proposal type gateway_init as 3rd item", () => { + should(trs.args[2]).equal("gateway_init"); + }); + + it("should set content.gateway", () => { + should(trs.args[3]).have.property("gateway").and.equal("name"); + }); + + it("should set content.members", () => { + should(trs.args[3]).have.property("members").and.eql(["address1", "address2", "address3"]); + }); + + it("should set proposalEndheight", () => { + should(trs.args[4]).be.type("number").and.equal(25000); + }); + }); + }); + }); + + describe("#updateGatewayMember", () => { + var updateGatewayMember; + var options; + var trs; + + beforeEach(() => { + updateGatewayMember = proposal.updateGatewayMember; + options = { + gatewayName: 'name', + fromAddress: "fromAddress", + toAddress: "toAddress", + proposalEndHeight: 30000 + } + trs = updateGatewayMember(options, "secret"); + }); + + afterEach(() => { + trs = null; + }); + + it("should have property updateGatewayMember", () => { + (proposal).should.have.property("updateGatewayMember"); + }); + + it("should be function", () => { + (updateGatewayMember).should.be.type("function"); + }); + + it("should create updateGatewayMember transaction", () => { + (trs).should.be.ok; + (trs).should.be.type("object"); + }); + + describe("returned updateGatewayMember transaction", () => { + it("should have id as string", () => { + (trs.id).should.be.type("string"); + }); + + it("should have type as number and equal 300", () => { + (trs.type).should.be.type("number").and.equal(300); + }); + + it("should have args as array with 5 items", () => { + (trs.args).should.be.an.Array().with.a.lengthOf(5); + }); + + it("should have fee and equal 10 XAS", () => { + (trs.fee).should.be.type("number").and.equal(10 * 1e8); + }); + + it("should have senderPublicKey as hex string", () => { + (trs.senderPublicKey).should.be.type("string").and.match(function (given) { + try { + new Buffer(trs.senderPublicKey, "hex"); + } catch (e) { + return false; + } + + return true; + }); + }); + + it("should have one signature as hex string in signatures array", () => { + (trs.signatures[0]).should.be.type("string").and.match(() => { + try { + new Buffer(trs.signatures[0], "hex") + } catch (e) { + return false; + } + return true; + }) + }); + + it("should be signed correctly", () => { + var result = asch.crypto.verify(trs); + + (result).should.be.ok; + }); + + it("should not be signed correctly now", () => { + trs.amount = 2626; + var result = asch.crypto.verify(trs); + (result).should.be.not.ok; + }); + + describe("args", () => { + it("should overwrite proposal title", () => { + let newOptions = cloneObject(options); + + let proposalTitle = "overwritten title"; + newOptions.proposalTitle = proposalTitle; + + let trs = updateGatewayMember(newOptions, "secret"); + should(trs.args[0]).be.type("string").and.equal("overwritten title"); + }); + + it("should overwrite proposal description", () => { + let newOptions = cloneObject(options); + + let proposalDesc = "overwritten description"; + newOptions.proposalDesc = proposalDesc; + + let trs = updateGatewayMember(newOptions, "secret"); + should(trs.args[1]).be.type("string").and.equal("overwritten description"); + }); + + it("should have proposal type gateway_update_member as 3rd item", () => { + should(trs.args[2]).equal("gateway_update_member"); + }); + + it("should set content.gateway", () => { + should(trs.args[3]).have.property("gateway").and.equal("name"); + }); + + it("should set content.from", () => { + should(trs.args[3]).have.property("from").and.equal("fromAddress"); + }); + + it("should set content.to", () => { + should(trs.args[3]).have.property("to").and.equal("toAddress"); + }); + + it("should set proposalEndheight", () => { + should(trs.args[4]).be.type("number").and.equal(30000); + }); + }); + }); + }); + + describe("#revokeGateway", () => { + var revokeGateway; + var options; + var trs; + + beforeEach(() => { + revokeGateway = proposal.revokeGateway; + options = { + gatewayName: 'name', + proposalEndHeight: 40000 + }; + trs = revokeGateway(options, "secret"); + }); + + afterEach(() => { + trs = null; + }); + + it("should have property revokeGateway", () => { + (proposal).should.have.property("revokeGateway"); + }); + + it("should be function", () => { + (revokeGateway).should.be.type("function"); + }); + + it("should create revokeGateway transaction", () => { + (trs).should.be.ok; + (trs).should.be.type("object"); + }); + + describe("returned revokeGateway transaction", () => { + it("should have id as string", () => { + (trs.id).should.be.type("string"); + }); + + it("should have type as number and equal 300", () => { + (trs.type).should.be.type("number").and.equal(300); + }); + + it("should have args as array with 5 items", () => { + (trs.args).should.be.an.Array().with.a.lengthOf(5); + }); + + it("should have fee and equal 10 XAS", () => { + (trs.fee).should.be.type("number").and.equal(10 * 1e8); + }); + + it("should have senderPublicKey as hex string", () => { + (trs.senderPublicKey).should.be.type("string").and.match(function (given) { + try { + new Buffer(trs.senderPublicKey, "hex"); + } catch (e) { + return false; + } + + return true; + }); + }); + + it("should have one signature as hex string in signatures array", () => { + (trs.signatures[0]).should.be.type("string").and.match(() => { + try { + new Buffer(trs.signatures[0], "hex") + } catch (e) { + return false; + } + return true; + }) + }); + + it("should be signed correctly", () => { + var result = asch.crypto.verify(trs); + + (result).should.be.ok; + }); + + it("should not be signed correctly now", () => { + trs.amount = 2727; + var result = asch.crypto.verify(trs); + (result).should.be.not.ok; + }); + + describe("args", () => { + it("should overwrite proposal title", () => { + let newOptions = cloneObject(options); + + let proposalTitle = "overwritten title"; + newOptions.proposalTitle = proposalTitle; + + let trs = revokeGateway(newOptions, "secret"); + should(trs.args[0]).be.type("string").and.equal("overwritten title"); + }); + + it("should overwrite proposal description", () => { + let newOptions = cloneObject(options); + + let proposalDesc = "overwritten description"; + newOptions.proposalDesc = proposalDesc; + + let trs = revokeGateway(newOptions, "secret"); + should(trs.args[1]).be.type("string").and.equal("overwritten description"); + }); + + it("should have proposal type gateway_revoke as 3rd item", () => { + should(trs.args[2]).equal("gateway_revoke"); + }); + + it("should set content.gateway", () => { + should(trs.args[3]).have.property("gateway").and.equal("name"); + }); + + it("should set proposalEndheight", () => { + should(trs.args[4]).be.type("number").and.equal(40000); + }); + }); + }); + }); + + describe("#activateProposal", () => { + var activateProposal; + var trs; + + beforeEach(() => { + activateProposal = proposal.activateProposal; + let tid = "agey510fjyihfeijf" + trs = activateProposal(tid, "secret"); + }); + + afterEach(() => { + trs = null; + }); + + it("should have property activateProposal", () => { + (proposal).should.have.property("activateProposal"); + }); + + it("should be function", () => { + (activateProposal).should.be.type("function"); + }); + + it("should create activateProposal transaction", () => { + (trs).should.be.ok; + (trs).should.be.type("object"); + }); + + describe("returned activateProposal transaction", () => { + it("should have id as string", () => { + (trs.id).should.be.type("string"); + }); + + it("should have type as number and equal 302", () => { + (trs.type).should.be.type("number").and.equal(302); + }); + + it("should have args as array with 1 item", () => { + (trs.args).should.be.an.Array().with.a.lengthOf(1); + }); + + it("should have fee and equal 0 XAS", () => { + (trs.fee).should.be.type("number").and.equal(0 * 1e8); + }); + + it("should have senderPublicKey as hex string", () => { + (trs.senderPublicKey).should.be.type("string").and.match(function (given) { + try { + new Buffer(trs.senderPublicKey, "hex"); + } catch (e) { + return false; + } + + return true; + }); + }); + + it("should have one signature as hex string in signatures array", () => { + (trs.signatures[0]).should.be.type("string").and.match(() => { + try { + new Buffer(trs.signatures[0], "hex") + } catch (e) { + return false; + } + return true; + }) + }); + + it("should be signed correctly", () => { + var result = asch.crypto.verify(trs); + + (result).should.be.ok; + }); + + it("should not be signed correctly now", () => { + trs.amount = 2828; + var result = asch.crypto.verify(trs); + (result).should.be.not.ok; + }); + + describe("args", () => { + it("should have transactionId to activate as only args item", () => { + should(trs.args[0]).be.type("string").and.equal("agey510fjyihfeijf"); + }); + }) + }); + }); + + + describe("#upvoteProposal", () => { + var upvoteProposal; + var trs; + + beforeEach(() => { + upvoteProposal = proposal.upvoteProposal; + let tid = "92fygeohqncorfhFwgef" + trs = upvoteProposal(tid, "secret"); + }); + + afterEach(() => { + trs = null; + }); + + it("should have property upvoteProposal", () => { + (proposal).should.have.property("upvoteProposal"); + }); + + it("should be function", () => { + (upvoteProposal).should.be.type("function"); + }); + + it("should create upvoteProposal transaction", () => { + (trs).should.be.ok; + (trs).should.be.type("object"); + }); + + describe("returned upvoteProposal transaction", () => { + it("should have id as string", () => { + (trs.id).should.be.type("string"); + }); + + it("should have type as number and equal 301", () => { + (trs.type).should.be.type("number").and.equal(301); + }); + + it("should have args as array with 1 item", () => { + (trs.args).should.be.an.Array().with.a.lengthOf(1); + }); + + it("should have fee and equal 0.1 XAS", () => { + (trs.fee).should.be.type("number").and.equal(0.1 * 1e8); + }); + + it("should have senderPublicKey as hex string", () => { + (trs.senderPublicKey).should.be.type("string").and.match(function (given) { + try { + new Buffer(trs.senderPublicKey, "hex"); + } catch (e) { + return false; + } + + return true; + }); + }); + + it("should have one signature as hex string in signatures array", () => { + (trs.signatures[0]).should.be.type("string").and.match(() => { + try { + new Buffer(trs.signatures[0], "hex") + } catch (e) { + return false; + } + return true; + }) + }); + + it("should be signed correctly", () => { + var result = asch.crypto.verify(trs); + + (result).should.be.ok; + }); + + it("should not be signed correctly now", () => { + trs.amount = 2929; + var result = asch.crypto.verify(trs); + (result).should.be.not.ok; + }); + + describe("args", () => { + it("should have upvoted transactionId as only args item", () => { + should(trs.args[0]).be.type("string").and.equal("92fygeohqncorfhFwgef"); + }); + }); + }); + }); +}); diff --git a/types/index.d.ts b/types/index.d.ts index a37ae77..35e81fe 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -157,6 +157,62 @@ interface Uia { createTransfer: (currency: string, amount: string, recipientId: string, message: string, secret: string, secondSecret?: string) => MainchainTransaction; } +/* + proposal.js +*/ +interface RegisterGatwayOptions { + gatewayName: string; + gatewayDesc: string; + minmumMembers?: number; + updateInterval?: number; + currencySymbol: string; + currencyDesc: string; + currencyPrecision: number; + proposalTitle?: string; + proposalDesc?: string; + proposalEndHeight: number; +} + +interface InitGatewayOptions { + gatewayName: string; + gatewayMembers: string[]; + proposalTitle?: string; + proposalDesc?: string; + proposalEndHeight: number; +} + +interface UpdateGatewayMemberOptions { + gatewayName: string; + fromAddress: string; + toAddress: string; + proposalTitle?: string; + proposalDesc?: string; + proposalEndHeight: number; +} + +interface RevokeGatewayOptions { + gatewayName: string; + proposalTitle?: string; + proposalDesc?: string; + proposalEndHeight: number; +} + +interface Proposal { + registerGateway: (options: RegisterGatwayOptions, secret: string, secondSecret?: string) => MainchainTransaction; + initGateway: (options: InitGatewayOptions, secret: string, secondSecret?: string) => MainchainTransaction; + updateGatewayMember: (options: UpdateGatewayMemberOptions, secret: string, secondSecret?: string) => MainchainTransaction; + revokeGateway: (options: RevokeGatewayOptions, secret: string, secondSecret?: string) => MainchainTransaction; + activateProposal: (tid: string, secret: string, secondSecret?: string) => MainchainTransaction; + upvoteProposal: (tid: string, secret: string, secondSecret?: string) => MainchainTransaction; +} + +/* + gateway.js +*/ +interface Gateway { + registerMember: (gateway: string, memberPublicKey: string, secret: string, secondSecret?: string) => MainchainTransaction; +} + /* options.js */ @@ -203,6 +259,8 @@ declare const asch_js: { transaction: Transaction, vote: Vote, uia: Uia, + proposal: Proposal, + gateway: Gateway, options: Options, utils: { slots: Slots,