This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BaseTrie = require('merkle-patricia-tree/baseTrie') | |
const TrieNode = require('merkle-patricia-tree/trieNode') | |
const toNibbleArray = (bytes) => { | |
let nibbles = [] | |
bytes.forEach((b) => { | |
nibbles.push(parseInt(b / 16)) | |
nibbles.push(b % 16) | |
}) | |
return Buffer.from(nibbles) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3') | |
const BLOCK_NUMBER_PER_DAY = 24 * 60 * 4 | |
const contractJson = require('../../build/contracts/MyToken') | |
class Faucet { | |
constructor(address, fromAddress) { | |
this.provider = new Web3(new Web3.providers.HttpProvider("http://localhost:7545")) | |
this.myToken = new this.provider.eth.Contract(contractJson.abi, address, {from: fromAddress}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Faucet = require('../src/model/faucet') | |
const CONTRACT_ADDRESS = '0xadDf5bC8b45571D94e2FD46Bfb81f8dD6D6f9FA0' | |
const FROM_ADDRESS = '0x259de638f0d6d79dfa084a810c1356d4d575b62e' | |
describe('Faucet', function () { | |
describe('init', function () { | |
it('should be return instance', async () => { | |
const ins = new Faucet(CONTRACT_ADDRESS, FROM_ADDRESS) | |
expect(ins).toBeDefined() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3') | |
const Faucet = require('./faucet') | |
const BLOCK_NUMBER_PER_DAY = 24 * 60 * 4 | |
const contractJson = require('../../build/contracts/MyToken') | |
class FaucetWithProvider extends Faucet { | |
constructor(provider, address, fromAddress) { | |
super(address, fromAddress) | |
this.provider = new Web3(provider) | |
this.myToken = new this.provider.eth.Contract(contractJson.abi, address, {from: fromAddress}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Mock web3 as __tests__/__mocks__/web3.js */ | |
// const web3 = jest.genMockFromModule('web3') | |
/* Mock web3-eth-contract */ | |
let mockWeb3EthContract = function() {} | |
function __setMockContract(mock) { | |
mockWeb3EthContract = mock | |
} | |
let blockNumber = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.6.5; | |
contract SimpleDonationManager { | |
uint256 immutable minDonation = 42; | |
uint256 immutable maxDonation = calcMaxDonation(); | |
address immutable owner; | |
constructor() public { | |
owner = msg.sender; | |
// Error: Immutables cannot be read in constructor. | |
// assert(minDonation <= maxDonation); | |
// Error: Immutables can only be assigned once. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('multi transfer in same block', async () => { | |
web3.extend({property: 'mine', methods: [{ name: 'start', call: 'miner_start', params:0}]}) | |
web3.extend({property: 'mine', methods: [{ name: 'stop', call: 'miner_stop', params:0}]}) | |
const instance = await MyERC20Token.new() | |
const beforeBlock = await web3.eth.getBlockNumber() | |
await web3.mine.stop() | |
// queued tx1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pify = require('pify') | |
async function queueTransaction(from, to, value, nonce, gasLimit, data) { | |
const response = await pify(web3.currentProvider.send)({ | |
jsonrpc: "2.0", | |
method: "eth_sendTransaction", | |
id: new Date().getTime(), | |
params: [ | |
{ | |
from: from, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >= 0.8.0; | |
contract CalledContract { | |
uint[] nums; | |
function onlyEven(uint256 a) external pure returns(uint) { | |
uint b = 300 / a; | |
require(b % 2 == 0, "Ups! Reverting"); | |
return b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.1; | |
contract ModExpContracts { | |
address public constant modExpAddress = 0x0000000000000000000000000000000000000005; | |
bytes public _result; | |
function modExp( | |
uint baseLength, |