formatting files
This commit is contained in:
parent
b8121ea213
commit
cc690f784d
42
index.js
42
index.js
|
@ -12,17 +12,17 @@ const config = require('./config');
|
||||||
const bot = require('./bot');
|
const bot = require('./bot');
|
||||||
|
|
||||||
var express = require('express'),
|
var express = require('express'),
|
||||||
cors = require('cors'),
|
cors = require('cors'),
|
||||||
helmet = require('helmet'),
|
helmet = require('helmet'),
|
||||||
app = express(),
|
app = express(),
|
||||||
bodyParser = require('body-parser'),
|
bodyParser = require('body-parser'),
|
||||||
jsonParser = bodyParser.json();
|
jsonParser = bodyParser.json();
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
|
|
||||||
// Receive a POST request at the url specified by an env. var.
|
// Receive a POST request at the url specified by an env. var.
|
||||||
app.post(`${config.urlEndpoint}`, jsonParser, function(req, res, next) {
|
app.post(`${config.urlEndpoint}`, jsonParser, function (req, res, next) {
|
||||||
if (!req.body || !req.body.action) {
|
if (!req.body || !req.body.action) {
|
||||||
bot.error('', 'Wrong format');
|
bot.error('', 'Wrong format');
|
||||||
return res.sendStatus(400);
|
return res.sendStatus(400);
|
||||||
|
@ -35,7 +35,7 @@ app.post(`${config.urlEndpoint}`, jsonParser, function(req, res, next) {
|
||||||
}, config.delayInMiliSeconds);
|
}, config.delayInMiliSeconds);
|
||||||
});
|
});
|
||||||
|
|
||||||
const processRequest = function(req, res) {
|
const processRequest = function (req, res) {
|
||||||
const eth = bot.eth;
|
const eth = bot.eth;
|
||||||
const from = config.sourceAddress;
|
const from = config.sourceAddress;
|
||||||
const to = bot.getAddress(req);
|
const to = bot.getAddress(req);
|
||||||
|
@ -45,25 +45,25 @@ const processRequest = function(req, res) {
|
||||||
const gasPricePromise = bot.getGasPrice();
|
const gasPricePromise = bot.getGasPrice();
|
||||||
|
|
||||||
Promise.all([amountPromise, gasPricePromise])
|
Promise.all([amountPromise, gasPricePromise])
|
||||||
.then(function(amount, gasPrice){
|
.then(function (amount, gasPrice) {
|
||||||
let transaction = sendTransaction(eth, from, to, amount, gasPrice);
|
let transaction = sendTransaction(eth, from, to, amount, gasPrice);
|
||||||
|
|
||||||
|
transaction
|
||||||
|
.then(function () {
|
||||||
|
return res.sendStatus(200);
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
bot.error(req.body, error);
|
||||||
|
});
|
||||||
|
|
||||||
transaction
|
|
||||||
.then(function() {
|
|
||||||
return res.sendStatus(200);
|
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function (error) {
|
||||||
bot.error(req.body, error);
|
bot.error(req.body, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
})
|
|
||||||
.catch(function(error) {
|
|
||||||
bot.error(req.body, error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendTransaction = function(eth, from, to, amount, gasPrice){
|
const sendTransaction = function (eth, from, to, amount, gasPrice) {
|
||||||
if (!config.debug){
|
if (!config.debug) {
|
||||||
|
|
||||||
eth.getTransactionCount(from, (err, nonce) => {
|
eth.getTransactionCount(from, (err, nonce) => {
|
||||||
eth.sendTransaction({
|
eth.sendTransaction({
|
||||||
|
@ -91,6 +91,6 @@ const sendTransaction = function(eth, from, to, amount, gasPrice){
|
||||||
}
|
}
|
||||||
|
|
||||||
const port = process.env.PORT || 8181
|
const port = process.env.PORT || 8181
|
||||||
app.listen(port, function(){
|
app.listen(port, function () {
|
||||||
bot.log('Autobounty listening on port', port);
|
bot.log('Autobounty listening on port', port);
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,58 +9,58 @@ let sob_comment = 'Current balance: 0.000000 ETH\nTokens: SNT: 2500.00 ANT: 25.0
|
||||||
|
|
||||||
// Fake requests
|
// Fake requests
|
||||||
let requests = [
|
let requests = [
|
||||||
{body: {action: 'created', comment: {body: 'Creating my first comment', user: {login: 'jomsdev'}}}},
|
{ body: { action: 'created', comment: { body: 'Creating my first comment', user: { login: 'jomsdev' } } } },
|
||||||
{body: {action: 'edited', comment: {body: 'Editing my comment', user: {login: 'jomsdev'}}}},
|
{ body: { action: 'edited', comment: { body: 'Editing my comment', user: { login: 'jomsdev' } } } },
|
||||||
{body: {action: 'edited', comment: {body: sob_comment, user: {login: 'status-open-bounty'}}}},
|
{ body: { action: 'edited', comment: { body: sob_comment, user: { login: 'status-open-bounty' } } } },
|
||||||
{body: {action: 'created', comment: {body: sob_comment, user: {login: 'status-open-bounty'}}}}
|
{ body: { action: 'created', comment: { body: sob_comment, user: { login: 'status-open-bounty' } } } }
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('Bot behavior', function() {
|
describe('Bot behavior', function () {
|
||||||
describe('#needsFunding()', function() {
|
describe('#needsFunding()', function () {
|
||||||
it('should return false because the comment is not from status-open-bounty', function() {
|
it('should return false because the comment is not from status-open-bounty', function () {
|
||||||
assert.isFalse(bot.needsFunding(requests[0]));
|
assert.isFalse(bot.needsFunding(requests[0]));
|
||||||
|
});
|
||||||
|
it('should return false because a user is editing a comment', function () {
|
||||||
|
assert.isFalse(bot.needsFunding(requests[1]));
|
||||||
|
});
|
||||||
|
it('should return false because status-open-bounty edited a comment', function () {
|
||||||
|
assert.isFalse(bot.needsFunding(requests[2]));
|
||||||
|
});
|
||||||
|
it('should return true, it is all right and we should fund', function () {
|
||||||
|
assert.isTrue(bot.needsFunding(requests[3]));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('should return false because a user is editing a comment', function() {
|
|
||||||
assert.isFalse(bot.needsFunding(requests[1]));
|
|
||||||
});
|
|
||||||
it('should return false because status-open-bounty edited a comment', function() {
|
|
||||||
assert.isFalse(bot.needsFunding(requests[2]));
|
|
||||||
});
|
|
||||||
it('should return true, it is all right and we should fund', function() {
|
|
||||||
assert.isTrue(bot.needsFunding(requests[3]));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#getAddress', function() {
|
describe('#getAddress', function () {
|
||||||
it('should return the address from a status-open-bounty bot comment', function() {
|
it('should return the address from a status-open-bounty bot comment', function () {
|
||||||
assert.equal(bot.getAddress(requests[3]),'0x3645fe42b1a744ad98cc032c22472388806f86f9');
|
assert.equal(bot.getAddress(requests[3]), '0x3645fe42b1a744ad98cc032c22472388806f86f9');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: test getAmount which involves call to github and bounty tags
|
// TODO: test getAmount which involves call to github and bounty tags
|
||||||
describe('#getAmount', function() {
|
describe('#getAmount', function () {
|
||||||
it('should fail and log that there is no bounty label for this issue', function() {
|
it('should fail and log that there is no bounty label for this issue', function () {
|
||||||
// Code
|
// Code
|
||||||
|
});
|
||||||
|
it('should fail and log that there are more than one bounty labels for this issue', function () {
|
||||||
|
// Code
|
||||||
|
});
|
||||||
|
it('should return the amount for the issue given the price per hour and the bounty label for this issue', function () {
|
||||||
|
// Code
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('should fail and log that there are more than one bounty labels for this issue', function() {
|
|
||||||
// Code
|
|
||||||
});
|
|
||||||
it('should return the amount for the issue given the price per hour and the bounty label for this issue', function() {
|
|
||||||
// Code
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: test getLabel which involves call to github and bounty tags
|
// TODO: test getLabel which involves call to github and bounty tags
|
||||||
describe('#getGasPrice', function() {
|
describe('#getGasPrice', function () {
|
||||||
it('should go to the gasStation and comeback with a reasonable number', function() {
|
it('should go to the gasStation and comeback with a reasonable number', function () {
|
||||||
bot.getGasPrice()
|
bot.getGasPrice()
|
||||||
.then(function(gasPrice) {
|
.then(function (gasPrice) {
|
||||||
assert.isNumber(gasPrice);
|
assert.isNumber(gasPrice);
|
||||||
})
|
})
|
||||||
.catch(function() {
|
.catch(function () {
|
||||||
assert.fail();
|
assert.fail();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue