I am using truffle to develop a simple smart contract.
I have the following contract:
contract Puppy {
enum State { good, bad }
State public status;
State public constant INITIAL_STATUS = State.good;
function Puppy() {
status = INITIAL_STATUS;
}
}
And I wish to test it as follows:
const Puppy = artifacts.require('./Puppy.sol')
contract('Puppy', () => {
it('sets the initial status to \'good\'', () => Puppy.deployed()
.then(instance => instance.status())
.then((status) => {
assert.equal(status, Puppy.State.good, 'Expected the status to be \'good\'')
}))
})
This throws TypeError: Cannot read property 'good' of undefined
If I change the test to
const Puppy = artifacts.require('./Puppy.sol')
contract('Puppy', () => {
it('sets the initial status to \'good\'', () => Puppy.deployed()
.then(instance => instance.status())
.then((status) => {
assert.equal(status, 0, 'Expected the status to be \'good\'')
}))
})
it passes.
How do I refer to the enum
from within the test?