Skip to content

Instantly share code, notes, and snippets.

View agawish's full-sized avatar

Amr Gawish agawish

View GitHub Profile
@agawish
agawish / Escrow.scilla
Last active January 4, 2019 17:54
Simple Escrow
(* Escrow contract *)
import ListUtils
(***************************************************)
(* Associated library *)
(***************************************************)
library Escrow
let one_msg =
@agawish
agawish / Survey.sol
Last active May 4, 2018 14:16
Survey DApp Solidity Code after "createSurvey functionality"
pragma solidity ^0.4.19;
/// @title Survey - A survey instant created by SurveyFactory to randomize the winning process of the fees
/// @author Amr Gawish
contract Survey {
/* Events */
event SurveyInitialized(address indexed owner, uint indexed surveyReward);
@agawish
agawish / survey_factory.js
Last active March 21, 2018 00:25
Survey-Dapp "Create Survey" test cases
describe('Create New Survey Test Cases', () => {
// ## Example #1
it(`1. Given that I’m the Survey Maker
2. When I try to create a new Survey and included the survey creation costs and survey reward
3. Then I should be able to get the created survey reference number and address`, () => {
return surveyFactory.createSurvey.call({ value: _surveyRewardAndCreationCost, from: _surveyMaker })
.then(([surveyId, surveyAddress]) => {
return surveyId;
}).should.eventually.be.bignumber.equals(0);
@agawish
agawish / survey.js
Last active March 21, 2018 00:26
Survey DApp Tests - After Creating Helpers
/* Loading all libraries from common */
const {
SurveyFactory, //Survey Factor Contract
Survey, //Survey Contract
BigNumber, //BigNumber from web3 (for ease to use)
CommonVariables, //Multiple common variables
expectRevert, //Check if the Solidity returns "revert" exception (usually result from require failed)
} = require('./helpers/common');
@agawish
agawish / common.js
Last active March 21, 2018 00:23
Helpers - common.js
/* Loading all imports */
const _ = require('lodash');
const expectRevert = require('./expectRevert');
const Survey = artifacts.require("./Survey.sol");
const SurveyFactory = artifacts.require("./SurveyFactory.sol");
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.use(require('chai-as-promised'))
@agawish
agawish / expectRevert.js
Created March 20, 2018 00:04
Helpers - expectRevert
// Inspired By:
// https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/test/helpers/assertRevert.js
const expect = require('chai').expect;
module.exports = async (promise) => {
try {
await promise;
assert.fail('Expected revert not received');
} catch (error) {
expect(error.message, `Expected "revert", got ${error} instead`).to.contain('revert');
@agawish
agawish / survey.js
Last active March 19, 2018 23:45
Survey DApp Tests shell
contract('Survey', _accounts => {
/* Initialization code here */
beforeEach(async () => {
/* Before Each Test here */
});
describe('[TEST_CASES_LOGICAL_GROUP_HERE]', () => {
it(`1. Given that I'm the ____
module.exports = {
networks: {
// Test RPC environment
development: {
host: "localhost",
port: 8545,
network_id: "*" //Listen to all networks
}
@agawish
agawish / init.sh
Last active March 2, 2018 20:03
Initialization of Survey Reward DApp
# Create DApp Directory
mkdir survey-reward-dapp
# Open DApp Directory
cd survey-reward-dapp
# Initialize the application using NPM (Follow through, or if you're happy with default just go with npm init -y
npm init
# Start by downloading Truffle (You can also install it globally by npm install -g truffle
@agawish
agawish / app.js
Last active May 3, 2017 12:46
Extending bot functionality to serve a public webpage
//Express
let express = require('express');
let app = express();
app.use(express.static('public'))
app.get('/', function(req, res){
res.sendFile('public/index.html', { root : __dirname});
});