Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Bajabob69 opened this issue Dec 13, 2021 · 0 comments
Open

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

Bajabob69 opened this issue Dec 13, 2021 · 0 comments

Comments

@Bajabob69
Copy link

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'
})

})

})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant