diff --git a/bot/index.js b/bot/index.js index 80fa895..f3b3a7a 100644 --- a/bot/index.js +++ b/bot/index.js @@ -58,9 +58,13 @@ function hasAddress (req) { function getAddress (req) { const commentBody = req.body.comment.body - const index = commentBody.search(contractAddressString) + contractAddressString.length + 1 - console.log("address: ", commentBody.substring(index, index + 42)) - return commentBody.substring(index, index + 42) + const index = commentBody.search(contractAddressString) + if (index === -1) { + return undefined + } + const addressIndex = index + contractAddressString.length + 1 + console.log('address: ', commentBody.substring(addressIndex, addressIndex + 42)) + return commentBody.substring(addressIndex, addressIndex + 42) } async function getLabel (req) { diff --git a/package.json b/package.json index 752de00..007d7d8 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "start": "node index.js", "debug": "node --inspect-brk index.js", - "test": "./node_modules/mocha/bin/mocha" + "test": "./node_modules/mocha/bin/mocha --timeout 5s" }, "author": "", "license": "ISC", diff --git a/test/test_bot.js b/test/test_bot.js index bb7f903..4c5adbe 100644 --- a/test/test_bot.js +++ b/test/test_bot.js @@ -4,7 +4,7 @@ const config = require('../config') const bot = require('../bot') // status-open-bounty comment from https://github.com/status-im/autobounty/issues/1 -const sobComment = 'Current balance: 0.000000 ETH\nTokens: SNT: 2500.00 ANT: 25.00\nContract address: 0x3645fe42b1a744ad98cc032c22472388806f86f9\nNetwork: Mainnet\n To claim this bounty sign up at https://openbounty.status.im and make sure to update your Ethereum address in My Payment Details so that the bounty is correctly allocated.\nTo fund it, send ETH or ERC20/ERC223 tokens to the contract address.' +const sobComment = 'Current balance: 0.000000 ETH\nTokens: SNT: 2500.00 ANT: 25.00\nContract address: [0x3645fe42b1a744ad98cc032c22472388806f86f9](https://etherscan.io/address/0x3645fe42b1a744ad98cc032c22472388806f86f9)\nNetwork: Mainnet\n To claim this bounty sign up at https://openbounty.status.im and make sure to update your Ethereum address in My Payment Details so that the bounty is correctly allocated.\nTo fund it, send ETH or ERC20/ERC223 tokens to the contract address.' const sobCommentWithWinner = 'Balance: 0.000000 ETH\nContract address: [0xe02fbffb3422ddb8e2227c3495f710ba4f8e0c10](https://etherscan.io/address/0xe02fbffb3422ddb8e2227c3495f710ba4f8e0c10)\nNetwork: Mainnet\nStatus: Pending maintainer confirmation\nWinner: foopang\nVisit [https://openbounty.status.im](https://openbounty.status.im) to learn more.' // Fake requests @@ -43,6 +43,9 @@ describe('Bot behavior', function () { it('should return the address from a status-open-bounty bot comment', function () { assert.equal(bot.getAddress(requests[3]), '0x3645fe42b1a744ad98cc032c22472388806f86f9') }) + it('should not return the address from a comment not containing an address', function () { + assert.isUndefined(bot.getAddress(requests[1])) + }) }) describe('#getAmount', function () {