Remix 断言库
断言
Assert.ok(value[, message])
value:<bool>message:<string>
测试值是否真实。如果错误,则返回对的 message 。
示例:
Assert.ok(true);
// OK
Assert.ok(false, "it\'s false");
// error: it's false
Assert.equal(actual, expected[, message])
actual:<uint | int | bool | address | bytes32 | string>expected:<uint | int | bool | address | bytes32 | string>message:<string>
测试actual实际值和expected 预期值是否相同。 不相同则返回 message 。
示例:
Assert.equal(string("a"), "a");
// OK
Assert.equal(uint(100), 100);
// OK
foo.set(200)
Assert.equal(foo.get(), 200);
// OK
Assert.equal(foo.get(), 100, "value should be 100");
// error: value should be 100
Assert.notEqual(actual, expected[, message])
actual:<uint | int | bool | address | bytes32 | string>expected:<uint | int | bool | address | bytes32 | string>message:<string>
测试actual实际值和expected 预期值是否不相同。 在失败的情况下返回对应的message。
示例:
Assert.notEqual(string("a"), "b");
// OK
foo.set(200)
Assert.notEqual(foo.get(), 200, "value should not be 200");
// error: value should not be 200
Assert.greaterThan(value1, value2[, message])
value1:<uint | int>value2:<uint | int>message:<string>
测试value1是否大于value2。不大于则返回message。
示例:
Assert.greaterThan(uint(2), uint(1));
// OK
Assert.greaterThan(uint(-2), uint(1));
// OK
Assert.greaterThan(int(2), int(1));
// OK
Assert.greaterThan(int(-2), int(-1), "-2 is not greater than -1");
// error: -2 is not greater than -1
Assert.lesserThan(value1, value2[, message])
value1:<uint | int>value2:<uint | int>message:<string>
测试value1是否小于value2。不小于则返回message。
示例:
Assert.lesserThan(int(-2), int(-1));
// OK
Assert.lesserThan(int(2), int(1), "2 is not lesser than 1");
// error: 2 is not lesser than 1