为什么我的合同状态没有变化



我正在创建一个solid的学习项目,它是一个基本的智能合约。

我有以下智能合约:

contract SmartContract {
uint256 public contractProperty = 10;
function changeProperty(int256 newVal) external {
contractProperty = uint256(newVal);
}
}

我正在运行以下测试:

const SmartContract = artifacts.require("SmartContract");
contract('SmartContract', function(accounts) {
var testInstance;
it('returns correctly', () => {
return SmartContract.deployed().then((instance) => {
testInstance = instance;
})
.then(() => {
testInstance.changeProperty(10000);
})
.then(() => {
return testInstance.contractProperty();
})
.then((val) => {
assert.equal(val.toString(), '10000'.toString());
});
});
});

我得到一个错误,预期10等于10000,这意味着合同属性不会改变。

我做错了什么?为什么我的智能合约状态没有改变?(我用松露和巧克力酱,硬度为0.8)

const SmartContract = artifacts.require('./SmartContract.sol');
require('chai').use(require('chai-as-promised')).should();
contract('SmartContract', function (accounts) {
var testInstance;
it('returns correctly', () => {
return SmartContract.deployed()
.then((instance) => {
testInstance = instance;
})
.then(() => {
return testInstance.changeProperty(10000); // return is required
})
.then(() => {
return testInstance.contractProperty(); // return is required
})
.then((val) => {
assert.equal(val.toString(), '10000'.toString());
});
});
});

没有{, ..., },我们不需要return

contract('SmartContract', function (accounts) {
var testInstance;
it('returns correctly', () => {
return SmartContract.deployed()
.then((instance) => {
testInstance = instance;
})
.then(() => testInstance.changeProperty(10000))
.then(() => testInstance.contractProperty())
.then((val) => {
assert.equal(val.toString(), '10000'.toString());
});
});
});

相关内容

  • 没有找到相关文章

最新更新