{"size": 2049, "ext": "js", "max_stars_repo_path": "proxy/unstructured_storage/test/Token_V1.js", "max_stars_repo_name": "hammeWang/upgradeability", "max_stars_repo_stars_event_min_datetime": "2019-07-21T05:53:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T03:06:45.000Z", "max_issues_repo_path": "proxy/unstructured_storage/test/Token_V1.js", "max_issues_repo_name": "hammeWang/upgradeability", "max_issues_repo_issues_event_min_datetime": "2019-10-17T15:49:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-08T21:22:47.000Z", "max_forks_repo_path": "proxy/unstructured_storage/test/Token_V1.js", "max_forks_repo_name": "hammeWang/upgradeability", "max_forks_repo_forks_event_min_datetime": "2019-08-15T08:26:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T18:57:12.000Z"}
{"max_stars_count": 102, "max_issues_count": 3, "max_forks_count": 35, "avg_line_length": 34.15, "max_line_length": 93, "alphanum_fraction": 0.672523182}
const Token_V0 = artifacts.require('Token_V0')
const Token_V1 = artifacts.require('Token_V1')
const encodeCall = require('./helpers/encodeCall')
const assertRevert = require('./helpers/assertRevert')
const shouldBehaveLikeTokenV0 = require('./behaviors/token_v0')
const OwnedUpgradeabilityProxy = artifacts.require('OwnedUpgradeabilityProxy')

contract('Token_V1', ([_, proxyOwner, tokenOwner, owner, recipient, anotherAccount]) => {

  beforeEach(async function () {
    const impl_v0 = await Token_V0.new()
    const proxy = await OwnedUpgradeabilityProxy.new({ from: proxyOwner })
    const initializeData = encodeCall('initialize', ['address'], [tokenOwner])
    await proxy.upgradeToAndCall(impl_v0.address, initializeData, { from: proxyOwner })

    const impl_v1 = await Token_V1.new()
    await proxy.upgradeTo(impl_v1.address, { from: proxyOwner })

    this.token = await Token_V1.at(proxy.address)
  })

  shouldBehaveLikeTokenV0(proxyOwner, tokenOwner, owner, recipient, anotherAccount)

  describe('burn', function () {
    const from = owner

    beforeEach(async function () {
      await this.token.mint(owner, 100, { from: tokenOwner })
    })

    describe('when the given amount is not greater than balance of the sender', function () {
      const amount = 100

      it('burns the requested amount', async function () {
        await this.token.burn(amount, { from })

        const balance = await this.token.balanceOf(from)
        assert.equal(balance, 0)
      })

      it('emits a burn event', async function () {
        const { logs } = await this.token.burn(amount, { from })

        assert.equal(logs.length, 1)
        assert.equal(logs[0].event, 'Burn')
        assert.equal(logs[0].args.burner, owner)
        assert.equal(logs[0].args.value, amount)
      })
    })

    describe('when the given amount is greater than the balance of the sender', function () {
      const amount = 101

      it('reverts', async function () {
        await assertRevert(this.token.burn(amount, { from }))
      })
    })
  })
})
