I am having trouble unit testing my contracts: I am using Mocha, Chai and calling truffle test
I am testing LoanRecord.sol
contract LoanRecord {
public bool on;
...
constructor(...){
...
on = false;
}
function external turnOn(){
on = true;
}
}
And testing in record.test.js:
var assert = require('chai').assert
var LoanRecord = artifacts.require("../../contracts/record/LoanRecord.sol");
contract ('Record', function (accounts) {
describe("#turnOn()", function () {
it("should turn on a loan record instance", async function () {
loanrecord = await LoanRecord.new(
1,
18,
0x0000000000000000000000000000000000000002,
0x0000000000000000000000000000000000000001,
"LOAN"
);
await assert.equal(loanrecord.on, false)
await loanrecord.turnOn()
await assert.equal(loanrecord.on, true)
});
});
However, I am recieving:
1) Contract: Record
#turnOn()
should turn on a loan record instance:
AssertionError: expected [Function] to equal false
at Context.<anonymous> (test/record.js:15:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Why does loanrecord.on
return [Function]
rather than a boolean type?
Fixed (with gitter@dwardu help too):
contract ('Record', function (accounts) {
describe("#turnOn()", function () {
it("should turn on a loan record instance", async function () {
loanrecord = await LoanRecord.new(
1,
18,
0x0000000000000000000000000000000000000002,
0x0000000000000000000000000000000000000001,
"LOAN"
);
var on = await loanrecord.on()
await assert.equal(on, false)
await loanrecord.turnOn()
var on = await loanrecord.on()
await assert.equal(on, true)
});
});
}