-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/eng 483 create jobs #19
Conversation
Pull Request Test Coverage Report for Build 127
💛 - Coveralls |
contracts/JobManager.sol
Outdated
@@ -5,21 +5,69 @@ import "zeppelin-solidity/contracts/math/SafeMath.sol"; | |||
contract JobManager { | |||
using SafeMath for uint; | |||
|
|||
enum MineralCategory { Null, Compute, Storage } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have a Null
category here? Seems unnecessary - the default can be Compute
or Storage
without any problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was to use this to check if a mineral exists for that index.
Given that it is not possible to create a Mineral with Null category, or update it to have Null category, the only way it has Null category is that it does not exist (see mineralIsValid function).
However I like your idea of storing the address who submitted the mineral. This would provide a cleaner way to check if the mineral exists. Will do that
} else if (_category == uint(MineralCategory.Storage)) { | ||
mc = MineralCategory.Storage; | ||
} else { | ||
revert(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, given that you both cannot create a mineral with category Null
and cannot update a mineral to have category Null
, I would say that this enum option can be removed.
contracts/JobManager.sol
Outdated
|
||
function mineralIsValid(uint _mineralId) public view returns (bool) { | ||
Mineral memory m = minerals[_mineralId]; | ||
return m.category != MineralCategory.Null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code does not permit that a mineral to have a Null
category. I would update this to verify that a mineral does in fact exist for that index and that maybe that there isn't already a job associated with it.
Naturally, this will be a bidding process with the best priced job winning (we'd think), but we'll assume first-come, first-serve for simplicity purposes, now.
Ex:
Mineral memory m = minerals[_mineralId];
return m.id < numberOfMinerals && m.jobId == 0
I would also call this something like - mineralIsAvailable
or something along those lines given that the point is to make sure we can create a job for it. Whenever you create a mineral, the default value of '0' will be assigned to the jobId and index jobs starting from 1.
contracts/TransmuteDPOS.sol
Outdated
p.pricePerStorageMineral = _pricePerStorageMineral; | ||
p.pricePerComputeMineral = _pricePerComputeMineral; | ||
p.blockRewardCut = _blockRewardCut; | ||
p.feeShare = _feeShare; | ||
} | ||
|
||
function resignAsProvider(address _provider) internal { | ||
require(providers[_provider].status != ProviderStatus.Unregistered); | ||
require(providerStatus(_provider) != ProviderStatus.Unregistered); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should check to ensure that the provider is Registered
vs not Unregistered
, for readability purposes.
@@ -112,14 +110,15 @@ contract TransmuteDPOS is TransmuteToken, RoundManager, ProviderPool { | |||
Provider storage p = providers[_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); | |||
ProviderStatus pStatus = providerStatus(_provider); | |||
require(_provider == msg.sender || pStatus == ProviderStatus.Registered); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have a temp variable here and not just use the function in the equality check like you did on line 102
?
test/JobManager.spec.js
Outdated
it('should fail if category is not MINERAL_COMPUTE or MINERAL_STORAGE', async () => { | ||
await assertFail( jm.submitMineral("test", 0) ); | ||
await jm.submitMineral("test", MINERAL_COMPUTE); | ||
await jm.submitMineral("test", MINEARL_STORAGE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MINERAL_STORAGE*
test/JobManager.spec.js
Outdated
require('truffle-test-utils').init(); | ||
|
||
contract('JobManager', accounts => { | ||
|
||
let jm; | ||
const MINERAL_COMPUTE = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These will need to be updated to 0 and 1
test/JobManager.spec.js
Outdated
|
||
it('should accept no name for Mineral', async () => { | ||
const mineralId = (await jm.numberOfMinerals.call()).toNumber(); | ||
await jm.submitMineral("", MINERAL_COMPUTE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably be associating minerals with the users who submitted them and requiring a non-empty string for a name. If I had created a few minerals, how I would I be able to search them with this architecture?
test/JobManager.spec.js
Outdated
}); | ||
}); | ||
|
||
it('should accept no name for Mineral', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with permitting this to be the case. Explanation below.
test/JobManager.spec.js
Outdated
const mineralId = (await jm.numberOfMinerals.call()).toNumber(); | ||
await jm.submitMineral("", MINERAL_COMPUTE); | ||
const mineral = await jm.minerals.call(mineralId); | ||
let [name, _] = mineral; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_
is not a reasonable name for a variable.
https://transmute.atlassian.net/browse/ENG-483
containsProvider()
function. Removed Provider.status and replaced it withproviderStatus
that usescontainsProvider
to determine if Provider isRegistered
orUnregistered