Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Added CI pipeline, linting, tests (#20)
Browse files Browse the repository at this point in the history
* Added Travis configuration
* Added linting configuration (and fixed linting issues)
* Added `docs/` folder
* Added tests for most methods
  • Loading branch information
rkalis committed Dec 22, 2018
1 parent b5dfe9a commit 2d702a7
Show file tree
Hide file tree
Showing 22 changed files with 17,689 additions and 81 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
docs/
9 changes: 9 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,9 @@
module.exports = {
"env": {
"mocha": true,
},
"extends": "airbnb-base",
"rules": {
"no-console": "off",
},
};
16 changes: 16 additions & 0 deletions .travis.yml
@@ -0,0 +1,16 @@
language: node_js

node_js:
- "8"
- "10"

script:
- npm run lint
- npm run test

after_success:
- npm run coverage

notifications:
email:
roscokalis+travis@gmail.com
8 changes: 5 additions & 3 deletions README.md
@@ -1,8 +1,10 @@
# truffle-assertions

[![npm version](https://badge.fury.io/js/truffle-assertions.svg)](https://www.npmjs.com/package/truffle-assertions)
[![npm](https://img.shields.io/npm/dt/truffle-assertions.svg)](https://www.npmjs.com/package/truffle-assertions)
[![npm](https://img.shields.io/npm/l/truffle-assertions.svg)](https://www.npmjs.com/package/truffle-assertions)
[![Build Status](https://travis-ci.org/rkalis/truffle-assertions.svg?branch=v1.0)](https://travis-ci.org/rkalis/truffle-assertions)
[![Coverage Status](https://img.shields.io/codecov/c/github/rkalis/truffle-assertions/v1.0.svg)](https://codecov.io/gh/rkalis/truffle-assertions/)
[![NPM Version](https://img.shields.io/npm/v/truffle-assertions.svg)](https://www.npmjs.com/package/truffle-assertions)
[![NPM Monthly Downloads](https://img.shields.io/npm/dm/truffle-assertions.svg)](https://www.npmjs.com/package/truffle-assertions)
[![NPM License](https://img.shields.io/npm/l/truffle-assertions.svg)](https://www.npmjs.com/package/truffle-assertions)

This package adds additional assertions that can be used to test Ethereum smart contracts inside Truffle tests.

Expand Down
Empty file.
47 changes: 47 additions & 0 deletions docs/kalis-me-tutorial-code/contracts/Casino.sol
@@ -0,0 +1,47 @@
pragma solidity ^0.4.23;

contract Casino {
address public owner;

event Play(address indexed player, uint256 betSize, uint8 betNumber, uint8 winningNumber);
event Payout(address winner, uint256 payout);

constructor() public {
owner = msg.sender;
}

function kill() external {
require(msg.sender == owner, "Only the owner can kill this contract");
selfdestruct(owner);
}

function fund() external payable {}

function bet(uint8 number) external payable {
require(msg.value <= getMaxBet(), "Bet amount can not exceed max bet size");
require(msg.value > 0, "A bet should be placed");

uint8 winningNumber = generateWinningNumber();
emit Play(msg.sender, msg.value, number, winningNumber);

if (number == winningNumber) {
payout(msg.sender, msg.value * 10);
}
}

function getMaxBet() public view returns (uint256) {
return address(this).balance / 100;
}

function generateWinningNumber() internal view returns (uint8) {
return uint8(block.number % 10 + 1); // Don't do this in production
}

function payout(address winner, uint256 amount) internal {
assert(amount > 0);
assert(amount <= address(this).balance);

winner.transfer(amount);
emit Payout(winner, amount);
}
}
23 changes: 23 additions & 0 deletions docs/kalis-me-tutorial-code/contracts/Migrations.sol
@@ -0,0 +1,23 @@
pragma solidity ^0.4.23;

contract Migrations {
address public owner;
uint public last_completed_migration;

modifier restricted() {
if (msg.sender == owner) _;
}

constructor() public {
owner = msg.sender;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
5 changes: 5 additions & 0 deletions docs/kalis-me-tutorial-code/migrations/1_initial_migration.js
@@ -0,0 +1,5 @@
var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
deployer.deploy(Migrations);
};

0 comments on commit 2d702a7

Please sign in to comment.