I have an ERC777 derived token, Enervator, which, aside from operatorBurn
, behaves correctly. For example, all the tests below pass, except “Burns correctly”, which causes the VM to break:
Error: Returned error: VM Exception while processing transaction: revert
at Object.ErrorResponse (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-core-requestmanager/~/web3-core-helpers/src/errors.js:29:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3-core-requestmanager/src/index.js:140:1
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:112:1
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-providers-http/src/index.js:96:1)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:208:1)
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:318:1)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:289:47)
at endReadableNT (_stream_readable.js:1178:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Here are my tests:
it('has the correct name', async function () {
const name = await this.manager.getTokenName()
assert.equal( name, 'Enervator' )
});
it('has the correct symbol', async function () {
const symbol = await this.manager.getTokenSymbol()
assert.equal( symbol, 'EOR' )
});
it('Sets supply correctly', async function () {
const newSupply = new BN('7727623693', 10)
const shiftedSupply = this.decimilisation.mul( newSupply )
await this.manager.addTokens(shiftedSupply)
const supply = await this.manager.getTotalSupply()
const retrievedNewSupply = supply.div(this.decimilisation)
const thisRetrievedNewSupply = parseInt(retrievedNewSupply.toString())
assert.equal( thisRetrievedNewSupply, '7727623693' )
});
it('Burns correctly', async function () {
const burnAmount = new BN('1000000000', 10)
const shiftedBurn = this.decimilisation.mul( burnAmount )
await this.manager.burnTokens(shiftedBurn)
const supply = await this.manager.getTotalSupply()
const retrievedNewSupply = supply.div(this.decimilisation)
const thisRetrievedNewSupply = parseInt(retrievedNewSupply.toString())
const supplyShouldEqual = 7727623693 - 1000000000
assert.equal( thisRetrievedNewSupply, supplyShouldEqual )
});
it('has the correct current TPES', async function () {
const TPES = await this.manager.getCurrentTPES()
const retrievedTPES = TPES.div(this.multiplier)
const currentTPES = retrievedTPES.toString()
assert.equal( currentTPES, '162494360000' )
});
it('has the correct old TPES', async function () {
const TPES = new BN('162494360000', 10)
const thisTPES = this.multiplier.mul(TPES)
await this.manager.setNewTPES(thisTPES)
const currentTPES = await this.manager.getCurrentTPES()
const oldTPES = await this.manager.getOldTPES()
const retrievedCurrentTPES = currentTPES.div(this.multiplier)
const thisCurrentTPES = retrievedCurrentTPES.toString()
const retrievedOldTPES = oldTPES.div(this.multiplier)
const thisOldTPES = retrievedOldTPES.toString()
assert.equal( thisOldTPES, '162494360000' )
assert.equal( thisCurrentTPES, '162494360000' )
});
it('has the correct per capita energy', async function () {
const perCapita = await this.manager.getPerCapitaEnergy()
const retrievedPerCapita = perCapita.div(this.multiplier)
const thisPerCapita = retrievedPerCapita.toString()
assert.equal( thisPerCapita, '22' )
});
it('has the correct unit value', async function () {
const pricePerMWh = await this.manager.getPricePerMWh()
const currentTPES = await this.manager.getCurrentTPES()
const oldTPES = await this.manager.getOldTPES()
const perCapita = await this.manager.getPerCapitaEnergy()
const derivedUnitValue = parseFloat( pricePerMWh.toString() ) * ( parseFloat( oldTPES.toString() ) / parseFloat( currentTPES.toString() ) ) / parseFloat( perCapita.toString() )
const thisDerivedUnitValue = ( derivedUnitValue ).toFixed( 2 )
const unitValue = await this.manager.getUnitValue()
const retrievedUnitValue = parseFloat(unitValue.toString())
const thisUnitValue = ( retrievedUnitValue / 2**64 ).toFixed( 2 )
assert.equal( thisDerivedUnitValue, thisUnitValue )
});
it('has the correct rate', async function () {
const code = ethers.utils.formatBytes32String( "USD" )
const rate = new DECIMAL(0.07)
const thisTwo = new DECIMAL(2)
const thisSixtyFour = new DECIMAL(64)
const thisMultiplier = thisTwo.pow(thisSixtyFour)
const thisNewBigRate = Math.round(thisMultiplier.mul(rate).toString())
await this.exchanger.setRate( code, thisNewBigRate.toString() )
const savedRate = BIG(await this.forex.getRate( code ))
const retrievedRate = savedRate.div(thisMultiplier)
const thisRetrievedRate = retrievedRate.toFixed(2)
assert.equal( thisRetrievedRate, rate.toString() )
});
it('deposits correctly', async function () {
const code = ethers.utils.formatBytes32String( "USD" )
const depositRef = ethers.utils.formatBytes32String( "USDDEP" )
const amount = '1000'
const bigAmount = new BN( amount, 10 )
const thisAmount = this.multiplier.mul(bigAmount)
await this.exchanger.deposit( '0xc220728701829A7351Fa3e16b11Aaf223543AAc3', depositRef, code, thisAmount )
const savedAmount = await this.deposit.getDepositedAmount( depositRef )
const retrievedAmount = savedAmount.div( this.multiplier )
const thisRetrievedAmount = retrievedAmount.toString()
assert.equal( thisRetrievedAmount, amount )
});
it('Buys correctly', async function () {
const buyRef = ethers.utils.formatBytes32String( "USDBUY" )
const depositRef = ethers.utils.formatBytes32String( "USDDEP" )
const amount = await this.deposit.getDepositedAmount( depositRef )
await this.exchanger.buy( '0xc220728701829A7351Fa3e16b11Aaf223543AAc3', buyRef, depositRef, amount )
const newDepositedAmount = await this.deposit.getDepositedAmount( depositRef )
const canWithdraw = await this.deposit.getCanWithdraw( depositRef )
assert.equal( newDepositedAmount, 0 )
assert.equal( canWithdraw, false )
});
Er, is this a bug in operatorBurn
, maybe? I’m not certain, so I thought I’d post here before logging an issue on GitHub.