2023-03-14 05:48:42 +00:00
|
|
|
const TestRevert = artifacts.require('TestRevert')
|
|
|
|
const truffleAssert = require('truffle-assertions')
|
2021-08-10 07:22:46 +00:00
|
|
|
|
2023-03-14 05:48:42 +00:00
|
|
|
async function expectRevert (promise) {
|
2021-08-10 07:22:46 +00:00
|
|
|
try {
|
2023-03-14 05:48:42 +00:00
|
|
|
await promise
|
2021-08-10 07:22:46 +00:00
|
|
|
} 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')
|
2021-08-10 07:22:46 +00:00
|
|
|
}
|
2023-03-14 05:48:42 +00:00
|
|
|
return
|
2021-08-10 07:22:46 +00:00
|
|
|
}
|
2023-03-14 05:48:42 +00:00
|
|
|
expect.fail('Expected an exception but none was received')
|
2021-08-10 07:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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')
|
2021-08-10 07:22:46 +00:00
|
|
|
|
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')
|
2021-08-10 07:22:46 +00:00
|
|
|
})
|
|
|
|
})
|