Avoid funding issues which already have a value in the desired token. Fixes #14

This commit is contained in:
Pedro Pombeiro 2018-03-26 10:29:50 +02:00
parent 7bbec12242
commit 6d848e59a9
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
2 changed files with 33 additions and 11 deletions

View File

@ -7,9 +7,9 @@ const config = require('../config')
const prices = require('./prices') const prices = require('./prices')
const github = require('./github') const github = require('./github')
const winnerString = 'Winner:' const winnerPrefix = 'Winner:'
const contractAddressString = 'Contract address: ' const contractAddressPrefix = 'Contract address: '
const paidString = 'Paid to:' const paidPrefix = 'Paid to:'
const logger = winston.createLogger({ const logger = winston.createLogger({
level: 'info', level: 'info',
@ -37,6 +37,8 @@ function needsFunding (req) {
return false return false
} else if (!hasAddress(req)) { } else if (!hasAddress(req)) {
return false return false
} else if (isFunded(req)) {
return false
} else if (hasWinner(req)) { } else if (hasWinner(req)) {
return false return false
} else if (isPaid(req)) { } else if (isPaid(req)) {
@ -45,24 +47,34 @@ function needsFunding (req) {
return true return true
} }
function isFunded (req) {
const prefix = `Tokens: ${config.token}: `
const index = req.body.comment.body.search(prefix)
if (index === -1) {
return false
}
const value = Number.parseFloat(req.body.comment.body.substring(index + prefix.length))
return value > 0
}
function isPaid (req) { function isPaid (req) {
return req.body.comment.body.search(paidString) !== -1 return req.body.comment.body.search(paidPrefix) !== -1
} }
function hasWinner (req) { function hasWinner (req) {
return req.body.comment.body.search(winnerString) !== -1 return req.body.comment.body.search(winnerPrefix) !== -1
} }
function hasAddress (req) { function hasAddress (req) {
return req.body.comment.body.search(contractAddressString) !== -1 return req.body.comment.body.search(contractAddressPrefix) !== -1
} }
function getAddress (req) { function getAddress (req) {
const commentBody = req.body.comment.body const commentBody = req.body.comment.body
const index = commentBody.search(contractAddressString) const index = commentBody.search(contractAddressPrefix)
if (index === -1) { if (index === -1) {
return undefined return undefined
} }
const addressIndex = index + contractAddressString.length + 1 const addressIndex = index + contractAddressPrefix.length + 1
console.log('address: ', commentBody.substring(addressIndex, addressIndex + 42)) console.log('address: ', commentBody.substring(addressIndex, addressIndex + 42))
return commentBody.substring(addressIndex, addressIndex + 42) return commentBody.substring(addressIndex, addressIndex + 42)
} }

View File

@ -4,8 +4,10 @@ const config = require('../config')
const bot = require('../bot') const bot = require('../bot')
// status-open-bounty comment from https://github.com/status-im/autobounty/issues/1 // 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](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 sobComment = 'Current balance: 0.000000 ETH\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.' const sobCommentWithWinner = 'Balance: 0.000000 ETH\nTokens: SNT: 2500.00 ANT: 25.00\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.'
const sobCommentForFundedBounty = 'Current balance: 0.000100 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 sobCommentForUnfundedBounty = 'Current balance: 0.000100 ETH\nTokens: SNT: 0.00 ANT: 0.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.'
// Fake requests // Fake requests
const requests = [ const requests = [
@ -14,6 +16,8 @@ const requests = [
{ headers: {'x-github-event': 'issue_comment'}, body: { action: 'created', comment: { body: sobComment, user: { login: 'status-open-bounty' } } } }, { headers: {'x-github-event': 'issue_comment'}, body: { action: 'created', comment: { body: sobComment, user: { login: 'status-open-bounty' } } } },
{ headers: {'x-github-event': 'issue_comment'}, body: { action: 'edited', repository: { owner: { login: 'status-im' }, name: 'autobounty' }, issue: { labels: ['bounty', 'bounty-xl'], number: 1 }, comment: { body: sobComment, user: { login: 'status-open-bounty' } } } }, { headers: {'x-github-event': 'issue_comment'}, body: { action: 'edited', repository: { owner: { login: 'status-im' }, name: 'autobounty' }, issue: { labels: ['bounty', 'bounty-xl'], number: 1 }, comment: { body: sobComment, user: { login: 'status-open-bounty' } } } },
{ headers: {'x-github-event': 'issue_comment'}, body: { action: 'edited', repository: { owner: { login: 'status-im' }, name: 'autobounty' }, issue: { labels: ['bounty', 'bounty-xl'], number: 1 }, comment: { body: sobCommentWithWinner, user: { login: 'status-open-bounty' } } } }, { headers: {'x-github-event': 'issue_comment'}, body: { action: 'edited', repository: { owner: { login: 'status-im' }, name: 'autobounty' }, issue: { labels: ['bounty', 'bounty-xl'], number: 1 }, comment: { body: sobCommentWithWinner, user: { login: 'status-open-bounty' } } } },
{ headers: {'x-github-event': 'issue_comment'}, body: { action: 'edited', repository: { owner: { login: 'status-im' }, name: 'autobounty' }, issue: { labels: ['bounty', 'bounty-xl'], number: 1 }, comment: { body: sobCommentForFundedBounty, user: { login: 'status-open-bounty' } } } },
{ headers: {'x-github-event': 'issue_comment'}, body: { action: 'edited', repository: { owner: { login: 'status-im' }, name: 'autobounty' }, issue: { labels: ['bounty', 'bounty-xl'], number: 1 }, comment: { body: sobCommentForUnfundedBounty, user: { login: 'status-open-bounty' } } } },
{ headers: {'x-github-event': 'labels'}, body: { action: 'created' } } { headers: {'x-github-event': 'labels'}, body: { action: 'created' } }
] ]
@ -34,9 +38,15 @@ describe('Bot behavior', function () {
it('should return false because issue already has a winner', function () { it('should return false because issue already has a winner', function () {
assert.isFalse(bot.needsFunding(requests[4])) assert.isFalse(bot.needsFunding(requests[4]))
}) })
it('should return false because the action is not related to issue comments', function () { it('should return false because issue is already funded', function () {
assert.isFalse(bot.needsFunding(requests[5])) assert.isFalse(bot.needsFunding(requests[5]))
}) })
it('should return true because issue is not yet funded', function () {
assert.isTrue(bot.needsFunding(requests[6]))
})
it('should return false because the action is not related to issue comments', function () {
assert.isFalse(bot.needsFunding(requests[7]))
})
}) })
describe('#getAddress', function () { describe('#getAddress', function () {