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 express = require('express') | |
const graphqlHTTP = require('express-graphql') | |
const Web3 = require('web3') | |
const TFcontract = require('truffle-contract') | |
const MetaCoinArtifact = require('./build/contracts/Metacoin') | |
const MetCoinContract = TFcontract(MetaCoinArtifact) | |
MetCoinContract.setProvider(new Web3.providers.HttpProvider('http://localhost:8545')) | |
const { genGraphQlProperties } = require('ethereum-to-graphql') |
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 genOutputFn = (outputTypesDef) => { | |
return (result) => { | |
const resultsIsArr = Array.isArray(result) | |
const outputTypesDefIsArray = Array.isArray(outputTypesDef) | |
const combined = zipOutputWithResults(resultsIsArr, outputTypesDefIsArray, result, outputTypesDef) | |
return combined.reduce((out, current) => { | |
let { key, name, result } = current | |
if (key === 'value') { | |
if (Array.isArray(result)) { |
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
describe('Testing Mycreated fail cases:', async function () { | |
let result = '' | |
it('should fail to create an event because eventName is not a string', async function () { | |
result = await this.Contract.createEvent(123456, _eventDescription, _eventWebsite, _eventDate, _location, { from: mainAccount }) | |
assert.equal(result.receipt.status, hex.fail, 'TX status should fail') | |
}) | |
it('should have Mycreatd list be empty', async function () { | |
let CreatedList = await this.Contract.getMyCreatedEvents.call(4, 1) | |
assert.deepEqual(convertBigNumArr(CreatedList), ['0', '0', '0', '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
it('should fail to create an event because eventName is not a string', async function () { | |
let op1 = await this.Contract.createEvent(123456, _eventDescription, _eventWebsite, _eventDate, _location, { from: mainAccount }) | |
assert.equal(op1.receipt.status, hex.fail, 'TX status should fail') | |
let CreatedList = await this.Contract.getMyCreatedEvents.call(4, 1) | |
assert.deepEqual(convertBigNumArr(CreatedList), ['0', '0', '0', '0']) | |
let EventList = await this.Contract.getAllEvents.call(4, 1) | |
assert.deepEqual(convertBigNumArr(EventList), ['0', '0', '0', '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
async function handleTestFn(method, inputs) { | |
try { | |
return await method(...inputs) | |
} catch(e) { | |
return e.receipt | |
} | |
} | |
it('should fail to create an event because eventName is not a string', async function () { | |
let op1 = await handleTestFn(this.Contract.createEvent, [123456, _eventDescription, _eventWebsite, _eventDate, _location, { from: mainAccount }]) |
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 sourceFn = ({ contract, method, outputMapper, isCall = true, options }) => { | |
return async function () { | |
try { | |
const instance = await contract.deployed() | |
const fn = (isCall) | |
? instance[method].call(...Object.values(arguments)) | |
: instance[method](...Object.values(arguments), options) | |
const data = await fn | |
return outputMapper(data) | |
} catch (e) { |
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.4.18; | |
contract DB { | |
uint public data; | |
function updateData(uint _val) public { | |
data = _val; | |
} | |
} |
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.4.18; | |
contract Worker1 { | |
uint public n; | |
address public sender; | |
function setN(uint _n) public { | |
n = _n; | |
sender = msg.sender; | |
} |
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.4.18; | |
contract Worker1 { | |
uint public n; | |
address public sender; | |
function setN(uint _n) public { | |
n = _n; | |
sender = msg.sender; |
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.4.18; | |
contract D { | |
uint public n; | |
address public sender; | |
function callSetN(address _e, uint _n) public { | |
_e.call(bytes4(keccak256("setN(uint256)")), _n); // E's storage is set, D is not modified | |
} | |
function callcodeSetN(address _e, uint _n) public { |
NewerOlder