-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from transmute-industries/feat/ENG-482-mineral
Feat/eng 482 mineral
- Loading branch information
Showing
5 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |