Skip to content

Commit

Permalink
Merge pull request #18 from transmute-industries/feat/ENG-482-mineral
Browse files Browse the repository at this point in the history
Feat/eng 482 mineral
  • Loading branch information
gjgd committed Jul 24, 2018
2 parents 160e06b + 33868ff commit ed11f66
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Transmute Network Contracts

[![Build Status](https://travis-ci.org/transmute-industries/network-contracts.svg?branch=master)](https://travis-ci.org/transmute-industries/network-contracts)

[![Coverage Status](https://coveralls.io/repos/github/transmute-industries/network-contracts/badge.svg?branch=master)](https://coveralls.io/github/transmute-industries/network-contracts?branch=master)
# Transmute Network Contracts [![Build Status](https://travis-ci.org/transmute-industries/network-contracts.svg?branch=master)](https://travis-ci.org/transmute-industries/network-contracts) [![Coverage Status](https://coveralls.io/repos/github/transmute-industries/network-contracts/badge.svg?branch=master)](https://coveralls.io/github/transmute-industries/network-contracts?branch=master)

This repo contains smart contracts that are under development.

Check out the [wiki](https://github.com/transmute-industries/network-contracts/wiki) for more info!

```
npm i
npm run test
Expand Down
25 changes: 25 additions & 0 deletions contracts/JobManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pragma solidity ^0.4.24;

import "zeppelin-solidity/contracts/math/SafeMath.sol";

contract JobManager {
using SafeMath for uint;

event MineralAdded (
uint id,
string name
);

struct Mineral {
string name;
}

uint public numberOfMinerals;
mapping(uint => Mineral) public minerals;

function submitMineral(string _name) external {
minerals[numberOfMinerals] = Mineral(_name);
emit MineralAdded(numberOfMinerals, _name);
numberOfMinerals = numberOfMinerals.add(1);
}
}
4 changes: 2 additions & 2 deletions contracts/TransmuteDPOS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ contract TransmuteDPOS is TransmuteToken, RoundManager, ProviderPool {
function bond(address _provider, uint _amount) external {
require(_amount > 0);
Provider storage p = providers[_provider];
// A delegator is only allowed to bond to an Unregistered provider if the provider is himself
// otherwise _provider has to be associated with a Registered provider
// A delegator is only allowed to bond to himself (in which case he wants to be a Provider)
// or to a Registered Provider
require(_provider == msg.sender || p.status == ProviderStatus.Registered);
// Check if delegator has not already bonded to some address
require(delegators[msg.sender].delegateAddress == address(0));
Expand Down
2 changes: 2 additions & 0 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const TestTransmuteDPOS = artifacts.require('./TestTransmuteDPOS.sol');
const RoundManager = artifacts.require('./RoundManager.sol');
const SortedDoublyLL = artifacts.require('./SortedDoublyLL.sol');
const TestProviderPool = artifacts.require('./TestProviderPool.sol');
const JobManager = artifacts.require('./JobManager.sol');

module.exports = deployer => {
deployer.deploy(TST);
Expand All @@ -12,4 +13,5 @@ module.exports = deployer => {
deployer.deploy(RoundManager);
deployer.link(SortedDoublyLL, TestProviderPool);
deployer.deploy(TestProviderPool);
deployer.deploy(JobManager);
};
37 changes: 37 additions & 0 deletions test/JobManager.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const JobManager = artifacts.require('./JobManager.sol');
require('truffle-test-utils').init();

contract('JobManager', accounts => {

let jm;

describe('submitMineral', () => {

before(async () => {
jm = await JobManager.deployed();
});

it('should store the Mineral in the minerals mapping', async () => {
await jm.submitMineral('multiplication');
const mineral = await jm.minerals.call(0);
assert.equal('multiplication', mineral);
});

it('should increase the value of numberOfMinerals', async () => {
const numberOfMinerals = await jm.numberOfMinerals.call();
await jm.submitMineral('addition');
assert.deepEqual(numberOfMinerals.add(1), await jm.numberOfMinerals.call())
});

it('should emit a MineralAdded event', async () => {
let result = await jm.submitMineral('division');
assert.web3Event(result, {
event: 'MineralAdded',
args: {
id: 2,
name: 'division',
}
});
});
});
});

0 comments on commit ed11f66

Please sign in to comment.