Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
solc 4.24
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Le Bars committed Jul 27, 2018
1 parent 609b002 commit 336aee3
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 22 deletions.
1 change: 0 additions & 1 deletion contracts/EIP20Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
pragma solidity ^0.4.21;


contract EIP20Interface {
/* This is a slight change to the ERC20 base standard.
function totalSupply() constant returns (uint256 supply);
Expand Down
5 changes: 4 additions & 1 deletion contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
pragma solidity ^0.4.4;

pragma solidity ^0.4.24;

contract Migrations {

address public owner;

uint public last_completed_migration;

modifier restricted() {
Expand Down
2 changes: 1 addition & 1 deletion contracts/RGETokenInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./EIP20Interface.sol";

Expand Down
4 changes: 2 additions & 2 deletions contracts/RougeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./SimpleRougeCampaign.sol";

Expand All @@ -14,7 +14,7 @@ import "./RougeRegistry.sol";

contract RougeFactory is RougeRegistry {

string public version = '0.8';
string public version = '0.9';

// The Rouge Token contract address
RGETokenInterface public rge;
Expand Down
2 changes: 1 addition & 1 deletion contracts/RougeFactoryInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./RGETokenInterface.sol";

Expand Down
4 changes: 3 additions & 1 deletion contracts/RougeRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./RougeRegistryInterface.sol";

Expand All @@ -10,6 +10,7 @@ contract RougeRegistry is RougeRegistryInterface {

mapping (address => bool) public is_issuer;
mapping (address => bool) public is_campaign;
mapping (address => uint256) public campaign_index;
mapping (address => address[]) campaigns;

function add_campaign(address _issuer, address _a) internal {
Expand All @@ -20,6 +21,7 @@ contract RougeRegistry is RougeRegistryInterface {
all_campaigns.push(_a);
campaigns[_issuer].push(_a);
is_campaign[_a] = true;
campaign_index[_a] = all_campaigns.length - 1;
}

function get_all_count() public view returns(uint count) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/RougeRegistryInterface.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

contract RougeRegistryInterface {

Expand Down
22 changes: 15 additions & 7 deletions contracts/SimpleRougeCampaign.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
Simple campaign contracts
Simple campaign contract
*/

pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./RGETokenInterface.sol";

import "./RougeFactoryInterface.sol";

contract SimpleRougeCampaign {

string public version = '0.8';
string public version = '0.9';

// The Rouge Token contract address
RGETokenInterface public rge;
Expand Down Expand Up @@ -43,7 +43,15 @@ contract SimpleRougeCampaign {

// web3.eth.sign compat prefix XXX mv to lib
function prefixed(bytes32 _message) internal pure returns (bytes32) {
return keccak256("\x19Ethereum Signed Message:\n32", _message);
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _message));
}

function getInfo() public view returns (bytes) {
return abi.encodePacked(issuer, scheme, campaignExpiration, name);
}

function getState() public view returns (bytes) {
return abi.encodePacked(issuance, available, acquired, redeemed);
}

bytes4 public scheme;
Expand Down Expand Up @@ -108,7 +116,7 @@ contract SimpleRougeCampaign {
// _hash is any hashed msg that confirm issuer authorisation for the note acquisition
function acquire(bytes32 _hash, uint8 v, bytes32 r, bytes32 s) CampaignOpen public returns (bool success) {
require(msg.sender != issuer);
require(_hash == keccak256('acceptAcquisition', this, msg.sender));
require(_hash == keccak256(abi.encodePacked('acceptAcquisition', this, msg.sender)));
require(ecrecover(prefixed(_hash), v, r, s) == issuer);
return acquisition(msg.sender);
}
Expand Down Expand Up @@ -150,14 +158,14 @@ contract SimpleRougeCampaign {
// _hash is any hashed msg agreed between issuer and bearer
// WARNING: replay protection not implemented at protocol level
function redeem(bytes32 _hash, uint8 v, bytes32 r, bytes32 s) CampaignOpen public returns (bool success) {
require(_hash == keccak256('acceptRedemption', this, msg.sender));
require(_hash == keccak256(abi.encodePacked('acceptRedemption', this, msg.sender)));
require(ecrecover(prefixed(_hash), v, r, s) == issuer);
return redemption(msg.sender);
}

function acceptRedemption(address _bearer, bytes32 _hash, uint8 v, bytes32 r, bytes32 s)
CampaignOpen onlyBy(issuer) public returns (bool success) {
require(_hash == keccak256('acceptRedemption', this, _bearer));
require(_hash == keccak256(abi.encodePacked('acceptRedemption', this, _bearer)));
require(ecrecover(prefixed(_hash), v, r, s) == _bearer);
return redemption(_bearer);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/TestRGEToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./EIP20.sol";

Expand Down
5 changes: 4 additions & 1 deletion test/RougeFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract('RougeFactory', function(accounts) {
const estimate = await rge.newCampaign.estimateGas(issuance, deposit, {from: issuer, gas: 3000000});
// console.log('Base estimate newCampaign => ', estimate)

const result = await rge.newCampaign(issuance, deposit, {from: issuer, gas: estimate + 50000, gasPrice: web3.toWei(1, "gwei")})
const result = await rge.newCampaign(issuance, deposit, {from: issuer, gas: estimate + 60000, gasPrice: web3.toWei(1, "gwei")})

assert.equal(result.receipt.cumulativeGasUsed, estimate, "cumulativeGasUsed correctly predict");

Expand All @@ -63,6 +63,9 @@ contract('RougeFactory', function(accounts) {
const campaign_version = await campaign.version.call();
assert.equal(campaign_version, factory_version, "factory and campaign contract version are the same");

const campaign_state = await campaign.getState.call();
assert.equal(campaign_state, '0x0000000a000000000000000000000000', "return null state");

const issuer_balance_after = await rge.balanceOf.call(issuer);
assert.equal(issuer_balance_after.toNumber(), tokens - deposit, "issuer has sent tokens as a deposit to the factory");

Expand Down
13 changes: 8 additions & 5 deletions test/SimpleRougeCampaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const SimpleRougeCampaign = artifacts.require("./SimpleRougeCampaign.sol");

const tare = 0.1 * 10**6; /* tare price is 0.1 rge in beta phase */
const tokens = 1000 * 10**6; /* issuer RGE tokens before campaign start */
const gas = 2078845

const gas = 3000778
const new_campaign = async function(rge, issuer, issuance, deposit) {

const factory = await Factory.deployed();
Expand Down Expand Up @@ -59,7 +59,7 @@ contract('SimpleRougeCampaign', function(accounts) {

// expiration of the campaign in 2 days
const expiration = Math.trunc((new Date()).getTime() / 1000) + 60*60*24*2
await campaign.issue('0x2100', 'no acquisition/noredemtion campaign', expiration, {from: issuer});
await campaign.issue('0x02010000', 'no acquisition/noredemtion campaign', expiration, {gas: 2000000, from: issuer});

const available = await campaign.available.call();
assert.equal(available.toNumber(), issuance, "check notes available after issuance");
Expand Down Expand Up @@ -88,7 +88,7 @@ contract('SimpleRougeCampaign', function(accounts) {
const campaign = await new_campaign(rge, issuer, issuance, deposit);

const expiration = Math.trunc((new Date()).getTime() / 1000) + 60*60*24*2
await campaign.issue('0x2100', 'issuer test', expiration, {from: issuer});
await campaign.issue('0x02010000', 'issuer test', expiration, {from: issuer});

await campaign.distributeNote(bearer, {from: issuer});

Expand Down Expand Up @@ -127,7 +127,7 @@ contract('SimpleRougeCampaign', function(accounts) {
const campaign = await new_campaign(rge, issuer, issuance, deposit);

const expiration = Math.trunc((new Date()).getTime() / 1000) + 60*60*24*2
await campaign.issue('0x2100', 'acceptRedemption Test', expiration, {from: issuer});
await campaign.issue('0x02010000', 'acceptRedemption Test', expiration, {from: issuer});

// call acquire with auth message and issuer signature
const auth1 = create_auth_hash('acceptAcquisition', campaign.address, bearer)
Expand All @@ -145,6 +145,9 @@ contract('SimpleRougeCampaign', function(accounts) {
const redeemed = await campaign.redeemed.call();
assert.equal(redeemed.toNumber(), 1, "note(s) redeemed after confirmRedemption");

const campaign_state = await campaign.getState.call();
assert.equal(campaign_state, '0x0000000a000000090000000100000001', "return null state");

await campaign.kill({from: issuer});

const burned = tare * (issuance - redeemed);
Expand Down

0 comments on commit 336aee3

Please sign in to comment.