laconicd-deprecated/tests/solidity/suites/exception/test/revert.js

36 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-03-14 05:48:42 +00:00
const TestRevert = artifacts.require('TestRevert')
const truffleAssert = require('truffle-assertions')
2023-03-14 05:48:42 +00:00
async function expectRevert (promise) {
try {
2023-03-14 05:48:42 +00:00
await promise
} catch (error) {
if (error.message.indexOf('revert') === -1) {
2023-03-14 05:48:42 +00:00
expect('revert').to.equal(error.message, 'Wrong kind of exception received')
}
2023-03-14 05:48:42 +00:00
return
}
2023-03-14 05:48:42 +00:00
expect.fail('Expected an exception but none was received')
}
contract('TestRevert', (accounts) => {
let revert
beforeEach(async () => {
revert = await TestRevert.new()
})
it('should revert', async () => {
2023-03-14 05:48:42 +00:00
await revert.try_set(10)
no = await revert.query_a()
assert.equal(no, '0', 'The modification on a should be reverted')
no = await revert.query_b()
assert.equal(no, '10', 'The modification on b should not be reverted')
no = await revert.query_c()
assert.equal(no, '10', 'The modification on c should not be reverted')
2023-03-14 05:48:42 +00:00
await revert.set(10)
no = await revert.query_a()
assert.equal(no, '10', 'The force set should not be reverted')
})
})