Skip to content

Parsing Error:Unexpected token, expected"," #32

@Bajabob69

Description

@Bajabob69

I can't figure this out I have been trying for hours now.

[{
"resource": "/c:/Users/Robert Threadgill/Test Project/starter_kit/test/EthSwap.test.js",
"owner": "eslint",
"severity": 8,
"message": "Parsing error: Unexpected token, expected ","\n\n 96 | assert.equal(event.amount.toString(), tokens('100').toString())\n 97 | assert.equal(event.rate.toString(), '100'\n> 98 | })\n | ^\n 99 | })\n 100 | \n 101 | })",
"source": "eslint",
"startLineNumber": 98,
"startColumn": 5,
"endLineNumber": 98,
"endColumn": 5
}]C:\Users\Robert Threadgill\Test Project\starter_kit\test\EthSwap.test.js

const { assert } = require('chai')

const Token = artifacts.require('Token')
const EthSwap = artifacts.require('EthSwap')

require('chai')
.use(require('chai-as-promised'))
.should()

function tokens(n) {
return web3.utils.toWei(n, 'ether')
}

contract('EthSwap', ([deployer, investor]) => {
let token, ethSwap

before(async () => {
token = await Token.new()
ethSwap = await EthSwap.new(token.address)
// Transfer all token to EthSwap (1 Million)
await token.transfer(ethSwap.address, tokens('1000000'))
})
})

describe('Token deployment', async () => {
it('contract has a name', async () => {
let token = await Token.new()
const name = await token.name()
assert.equal(name, 'DApp Token')
})
})

describe('EthSwap deployment', async () => {
it('contract has a name', async () => {
let ethSwap = await EthSwap.new()
const name = await ethSwap.name()
assert.equal(name, 'EthSwap Instant Exchange')
})
})

describe('buyTokens()', async () => {
let result

before(async () => {
  // Purchase tokens before each example
  result = await EthSwap.buyTokens({ from: investor, value: web3.utils.toWei('1', 'ether') })
})

})
it('Allows user to instantly purchase tokens from ethSwap for a fixed price', async () => {
// Check investor token balance after purchase
let investorBalance = await token.balanceOf(investor)
assert.equal(investorBalance.toString(), tokens('100'))

  // Check ethSwap balance after purchase
  let ethSwapBalance
  ethSwapBalance = await token.balanceOf(ethSwap.address)
  assert.equal(ethSwapBalance.toString(), tokens('999900'))
  ethSwapBalance = await web3.eth.getBalance(ethSwap.address)
  assert.equal(ethSwapBalance.toString(), web3.utils.toWei('1', 'Ether'))

  const event = result.logs[0].args
  assert.equal(event.account, investor)
  assert.equal(event.token, token.address)
  assert.equal(event.amount.toString(), tokens('100').toString())
  assert.equal(event.rate.toString(), '100')
 })

describe('sellTokens()', async () => {
let result

before(async () => {
// Investor must approve tokens before the purchase
await token.approve(ethSwap.address, ('100'), { from: investor })
// Investor sell tokens
results = await ethSwap.sellTokens(tokens('100'), { from: investor })
})

it('Allows user to instantly sell tokens to ethSwap for a fixed price', async () => {
  // Check investor token balance after purchase
  let investorBalance = await token.balanceOf(investor)
  assert.equal(investorBalance.toString(), tokens('0'))

  // Check ethSwap balance after purchase
  let ethSwapBalance
  ethSwapBalance = await token.balanceOf(ethSwap.address)
  assert.equal(ethSwapBalance.toString(), tokens('1000000'))
  ethSwapBalance = await web3.eth.getBalance(ethSwap.address)
  assert.equal(ethSwapBalance.toString(), web3.utils.toWei('0', 'Ether'))

  // Check logs to ensure event was emitted with correct data
  const event = result.logs[0].args
  assert.equal(event.account, investor)
  assert.equal(event.token, token.address)
  assert.equal(event.amount.toString(), tokens('100').toString())
  assert.equal(event.rate.toString(), '100'
})

})

})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions