• Karl Floersch's avatar
    feat: v0.3.0 release candidate (#603) · b799caab
    Karl Floersch authored
    * feat: Attempt to decode txs as RLP first (#563)
    Co-authored-by: default avatarsmartcontracts <smartcontracts@doge.org>
    
    * l2geth: remove eth_sendRawEthSignTransaction endpoint (#589)
    
    * feat[contracts]: Use standard RLP transaction format (#566)
    
    * feat[contracts]: Use standard RLP transaction format
    
    * fix[l2geth]: Encode transaction as RLP
    
    * fix: Correct gas estimation in integration tests
    
    * fix: Correct gas estimation in integration tests
    
    * Update packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_SequencerEntrypoint.sol
    Co-authored-by: default avatarben-chain <ben@pseudonym.party>
    
    * fix[contracts]: Use isCreate instead of checking target address
    
    * fix[contracts]: Minor optimization in SequencerEntrypoint
    
    * fix[contracts]: Pass max gas to contract call in EOA contract
    Co-authored-by: default avatarben-chain <ben@pseudonym.party>
    
    * feat[contracts]: Make ProxyEOA compatible with eip1967 (#592)
    
    * feat[contracts]: Make ProxyEOA compatible with eip1967
    
    * fix[contracts]: Fix bug introduced by indirect constant
    
    * chore[contracts]: Add changeset
    
    * Update .changeset/old-cycles-invite.md
    Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>
    
    * l2geth: remove ovmsigner (#591)
    
    * l2geth: remove ovmsigner
    
    Also reduce the diff
    
    Co-authored-by: smartcontracts
    
    * l2geth: add changeset
    
    * l2geth: set rlp encoded tx in txmeta in RPC layer (#644)
    
    * l2geth: set rlp encoded tx in txmeta in RPC layer
    
    * l2geth: remove extra setter of txmeta
    
    * chore: add changeset
    
    * feat: Have ExecutionManager pass data upwards (#643)
    
    * feat[contracts]: Make ExecutionManager return data
    
    * fix[l2geth]: fix linting error
    
    * fix[contracts]: Fix build error
    
    * fix[contracts]: fix failing unit tests
    
    * Add changeset
    Co-authored-by: default avatarKarl Floersch <karl@karlfloersch.com>
    
    * rpc: only allow txs with no calldata when there is value (#645)
    
    * l2geth: api checks for 0 value
    
    * chore: add changeset
    
    * l2geth: remove check for specific gasprice
    
    * feat[contracts]: Add value transfer support to ECDSAContractAccount (#619)
    
    * feat[contracts]: Use standard RLP transaction format (#566)
    
    * feat[contracts]: Use standard RLP transaction format
    
    * fix[l2geth]: Encode transaction as RLP
    
    * fix: Correct gas estimation in integration tests
    
    * fix: Correct gas estimation in integration tests
    
    * Update packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_SequencerEntrypoint.sol
    Co-authored-by: default avatarben-chain <ben@pseudonym.party>
    
    * fix[contracts]: Use isCreate instead of checking target address
    
    * fix[contracts]: Minor optimization in SequencerEntrypoint
    
    * fix[contracts]: Pass max gas to contract call in EOA contract
    Co-authored-by: default avatarben-chain <ben@pseudonym.party>
    
    * feat[contracts]: Add value transfer to contract account
    
    * fix[contracts]: Tweak transfer logic and add tests
    
    * fix[geth]: Remove logic that rejects value gt 0 txs
    
    * fix: nonce issue in rpc tests
    
    * fix: use correct wallet in rpc value tests
    
    * Update rpc.spec.ts
    
    * cleanup: remove double definition
    
    * chore: add changeset
    
    * chore: add changeset
    
    * tests: delete dead test
    
    * l2geth: log the tx value
    
    * l2geth: pass through zero value at top level
    
    * test: receipt passes
    
    * test: more specifically set balance
    Co-authored-by: default avatarben-chain <ben@pseudonym.party>
    Co-authored-by: default avatarMark Tyneway <mark.tyneway@gmail.com>
    
    * dtl: remove legacy encoding (#618)
    
    * dtl: remove legacy decoding
    
    * tests: remove dead test
    
    * chore: add changeset
    
    * Add Goerli v3 deployment (#651)
    
    * Add Goerli v3 deployment
    
    * Add Goerli v3 to README
    
    * dtlL fix syncing off by one (#687)
    
    * dtl: syncing off by one error
    
    * chore: add changeset
    
    * dtl: index the value field (#686)
    
    * chore: add changeset
    
    * chore: add changeset
    
    * dtl: pass through value field
    
    * core-utils: update and test toRpcString
    
    * lint: fix
    
    * l2geth: parse value fields
    
    * chore: add changeset
    
    * rpc: gas fixes (#695)
    
    * l2geth: prevent fees lower than 21000
    
    * l2geth: remove old check for too high tx gaslimit
    
    * tests: update to use new min gas estimated value
    
    * chore: add changeset
    
    * test: update expected values
    
    * test: remove dead test
    
    * examples: fix waffle example + gas changes in tests (#724)
    
    * examples: fix waffle example
    
    * tests: update gas price in assertion
    
    * chore: add changeset
    
    * l2geth: estimate gas assertion in decimal
    
    * test: use configurable key
    
    * ops: delete extra whitespace (#731)
    
    * fix: prevent eth sendtransaction (#725)
    
    * api: prevent unsafe calls
    
    * api: fill in txmeta
    
    * chore: add changeset
    
    * chore: add changeset
    
    * l2geth + contracts:  standard interface for systems contracts and userland contracts (#721)
    
    * l2geth: fix call returndata parsing
    
    * contracts: standardize simulateMessage and run to return bytes
    
    * chore: add changeset
    
    * chore: add changeset
    
    * l2geth: more simple decoding
    
    * contracts: remove named arguments
    
    * chore: fix linter errors
    
    * Add contract deployment to Kovan (#715)
    
    * fix: remove type check in rollup client (#750)
    
    * l2geth: remove tx type check in client
    
    * chore: add changeset
    
    * dtl: prevent null reference in L1 handler (#757)
    
    * dtl: prevent reference of null value
    
    * chore: add changeset
    
    * test: eth_call exceptions (#800)
    
    * feat[l2geth]: Pass up contract revert reasons during DoEstimateGas (#774)
    
    * wip: Starting work on geth revert reasons during estimate gas
    
    fix: error in comment
    
    fix: I got things backwards
    
    fix: Use UnpackValues instead of Unpack
    
    Update l2geth/accounts/abi/abi.go
    Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>
    
    * Add integration test for reverts
    
    fix: build error
    
    * chore: Add changeset
    Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>
    
    * chore: add changeset (#831)
    
    * Migrate ETH between gateways (#778)
    
    * add migrate ETH functionality
    
    * contracts: add eth gateway docstring (#832)
    Co-authored-by: default avatarMark Tyneway <mark.tyneway@gmail.com>
    Co-authored-by: default avatarsmartcontracts <smartcontracts@doge.org>
    Co-authored-by: default avatarMark Tyneway <mark.tyneway@gmail.com>
    Co-authored-by: default avatarsmartcontracts <kelvinfichter@gmail.com>
    Co-authored-by: default avatarben-chain <ben@pseudonym.party>
    Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>
    Co-authored-by: default avatarMaurelian <maurelian@protonmail.ch>
    Co-authored-by: default avatarKevin Ho <kevinjho1996@gmail.com>
    b799caab
erc20.spec.js 3.39 KB
/* External imports */
require('dotenv/config')
const { use, expect } = require('chai')
const { ethers } = require('ethers')
const { solidity } = require('ethereum-waffle')

/* Internal imports */
const { getArtifact } = require('./getArtifact')

use(solidity)

const config = {
  l2Url: process.env.L2_URL || 'http://127.0.0.1:8545',
  l1Url: process.env.L1_URL || 'http://127.0.0.1:9545',
  useL2: process.env.TARGET === 'OVM',
  privateKey: process.env.PRIVATE_KEY || '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
}

describe('ERC20 smart contract', () => {
  let ERC20,
    provider

  if (config.useL2) {
    provider = new ethers.providers.JsonRpcProvider(config.l2Url)
    provider.pollingInterval = 100
    provider.getGasPrice = async () => ethers.BigNumber.from(0)
  } else {
    provider = new ethers.providers.JsonRpcProvider(config.l1Url)
  }

  const wallet = new ethers.Wallet(config.privateKey).connect(provider)

  // parameters to use for our test coin
  const COIN_NAME = 'OVM Test Coin'
  const TICKER = 'OVM'
  const NUM_DECIMALS = 1

  describe('when using a deployed contract instance', () => {
    before(async () => {
      const Artifact__ERC20 = getArtifact(config.useL2)
      const Factory__ERC20 = new ethers.ContractFactory(
        Artifact__ERC20.abi,
        Artifact__ERC20.bytecode,
        wallet
      )

      // TODO: Remove this hardcoded gas limit
      ERC20 = await Factory__ERC20.connect(wallet).deploy(
        1000,
        COIN_NAME,
        NUM_DECIMALS,
        TICKER
      )
      await ERC20.deployTransaction.wait()
    })

    it('should assigns initial balance', async () => {
      const address = await wallet.getAddress()
      expect(await ERC20.balanceOf(address)).to.equal(1000)
    })

    it('should correctly set vanity information', async () => {
      const name = await ERC20.name()
      expect(name).to.equal(COIN_NAME)

      const decimals = await ERC20.decimals()
      expect(decimals).to.equal(NUM_DECIMALS)

      const symbol = await ERC20.symbol()
      expect(symbol).to.equal(TICKER)
    })

    it('should transfer amount to destination account', async () => {
      const freshWallet = ethers.Wallet.createRandom()
      const destination = await freshWallet.getAddress()
      const tx = await ERC20.connect(wallet).transfer(destination, 7)
      await tx.wait()
      const walletToBalance = await ERC20.balanceOf(destination)
      expect(walletToBalance.toString()).to.equal('7')
    })

    it('should emit Transfer event', async () => {
      const address = await wallet.getAddress()
      const tx = ERC20.connect(wallet).transfer(address, 7)
      await expect(tx)
        .to.emit(ERC20, 'Transfer')
        .withArgs(address, address, 7)
    })

    it('should not transfer above the amount', async () => {
      const address = await wallet.getAddress()
      const walletToBalanceBefore = await ERC20.balanceOf(address)
      await expect(ERC20.transfer(address, 1007)).to.be.reverted
      const walletToBalanceAfter = await ERC20.balanceOf(address)
      expect(walletToBalanceBefore).to.eq(walletToBalanceAfter)
    })

    it('should not transfer from empty account', async () => {
      const emptyWallet = ethers.Wallet.createRandom()
      const address = await emptyWallet.getAddress()
      const ERC20FromOtherWallet = ERC20.connect(emptyWallet)
      await expect(ERC20FromOtherWallet.transfer(address, 1)).to.be
        .reverted
    })
  })
})