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

Commit

Permalink
add scheme param, campaign contract v0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Le Bars committed Jul 26, 2018
1 parent 0d15f68 commit aeba4ae
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
2 changes: 2 additions & 0 deletions contracts/RGETokenInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ contract RGETokenInterface is EIP20Interface {

address public factory;

function setFactory(address _factory) public;

function newCampaign(uint32 _issuance, uint256 _value) public;

event Burn(address indexed burner, uint256 value);
Expand Down
9 changes: 6 additions & 3 deletions contracts/RougeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ contract RougeFactory is RougeRegistry {
tare = _tare;
}

event NewRougeCampaign(address issuer, address campaign, uint32 _issuance);
event NewCampaign(address issuer, address campaign, uint32 issuance);

function createCampaign(address _issuer, uint32 _issuance, uint256 _tokens) public {

// only rge contract can call createCampaign
// require(msg.sender == address(rge));

SimpleRougeCampaign c = new SimpleRougeCampaign(_issuer, _issuance, rge, tare, this);

// XXX no need to check rge set ? transfer would revert ...
rge.transfer(c, _tokens); // transfer tokens to the campaign contract ...

emit NewRougeCampaign(_issuer, c, _issuance);
emit NewCampaign(_issuer, c, _issuance);

// XXX beta sugar getters / not stricly necessary...

Expand Down
16 changes: 11 additions & 5 deletions contracts/SimpleRougeCampaign.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import "./RougeFactoryInterface.sol";

contract SimpleRougeCampaign {

string public version = 'v0.7';
string public version = 'v0.8';

// The Rouge Token contract address
RGETokenInterface public rge;

// Factory address & tare settings (1 RGE)
// Factory address & tare settings
RougeFactoryInterface public factory;
uint256 public tare;

address issuer; // XXX todo owner = initial potential issuer, issuer can be changed ?
address public issuer; // XXX todo ? owner != initial issuer

modifier onlyBy(address _address) {
require(msg.sender == _address);
Expand All @@ -46,11 +46,14 @@ contract SimpleRougeCampaign {
return keccak256("\x19Ethereum Signed Message:\n32", _message);
}

bytes4 public scheme;
string public name;
bool public campaignIssued;
uint public campaignExpiration;

function issue(string _name, uint _campaignExpiration) onlyBy(issuer) public {
event Issuance(bytes4 scheme, string name, uint campaignExpiration);

function issue(bytes4 _scheme, string _name, uint _campaignExpiration) onlyBy(issuer) public {

// still possible to send RGE post creation, before issuing the campaign
uint256 rgeBalance = rge.balanceOf(this);
Expand All @@ -64,7 +67,10 @@ contract SimpleRougeCampaign {
campaignIssued = true;
campaignExpiration = _campaignExpiration;
available = issuance;

scheme = _scheme;

emit Issuance(_scheme, _name, _campaignExpiration);

}

modifier CampaignOpen() {
Expand Down
26 changes: 22 additions & 4 deletions test/RougeFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const RGEToken = artifacts.require("./TestRGEToken.sol");
const Factory = artifacts.require("./RougeFactory.sol");
const SimpleRougeCampaign = artifacts.require("./SimpleRougeCampaign.sol");

const tare = 0.1 * 10**6; /* tare price is 0.1 rge in beta phase */
const tare = 0.1 * 10**6; /* tare price is 0.1 RGE in beta phase */

contract('RougeFactory', function(accounts) {

Expand Down Expand Up @@ -36,16 +36,34 @@ contract('RougeFactory', function(accounts) {
const issuer_balance_post = await rge.balanceOf.call(issuer);
assert.equal(issuer_balance_post.toNumber(), tokens, "issuer has receive tokens to create a campaign");

await rge.newCampaign(issuance, deposit, {from: issuer, gas: 2000000, gasPrice: web3.toWei(1, "gwei")})
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")})

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

const campaign_address = await factory.get_campaign.call(issuer, 0);

const event_NewCampaign_sign = web3.sha3('NewCampaign(address,address,uint32)')
// const event_Transfer_sign = web3.sha3('Transfer(address,address,uint256)')
result.receipt.logs.forEach( function(e) {
// console.log(e)
if (e.topics[0] === event_NewCampaign_sign) {

assert.equal(e.data.slice(2 + 24, 66), issuer.substr(2), "issuer first data of NewCampaign event");
assert.equal(e.data.slice(66 + 24, 130), campaign_address.substr(2), "campaign address 2nd data of NewCampaign event");
assert.equal(web3.toDecimal( '0x' + e.data.slice(130, 194)), issuance, "issuance 3nd data of NewCampaign event");

}
})

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");

const campaign_count = await factory.get_all_count.call();
assert.equal(campaign_count.toNumber(), 1, "one campaign has been created");

const campaign_address = await factory.get_campaign.call(issuer, 0);

const factory_balance = await rge.balanceOf.call(factory.address);
assert.equal(factory_balance.toNumber(), 0, "no tokens deposit in the factory");

Expand Down
9 changes: 5 additions & 4 deletions test/SimpleRougeCampaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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 new_campaign = async function(rge, issuer, issuance, deposit) {

Expand All @@ -18,7 +19,7 @@ const new_campaign = async function(rge, issuer, issuance, deposit) {
/* refill issuer tokens to test starting value */
await rge.giveMeRGE(tokens - issuer_balance_before, {from: issuer});

await rge.newCampaign(issuance, deposit, {from: issuer, gas: 2000000, gasPrice: web3.toWei(1, "gwei")})
await rge.newCampaign(issuance, deposit, {from: issuer, gas: gas, gasPrice: web3.toWei(1, "gwei")})
const campaign_address = await factory.get_last_campaign.call(issuer);

return SimpleRougeCampaign.at(campaign_address);
Expand Down Expand Up @@ -58,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('no acquisition/noredemtion campaign', expiration, {from: issuer});
await campaign.issue('0x2100', 'no acquisition/noredemtion campaign', expiration, {from: issuer});

const available = await campaign.available.call();
assert.equal(available.toNumber(), issuance, "check notes available after issuance");
Expand Down Expand Up @@ -87,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('issuer test', expiration, {from: issuer});
await campaign.issue('0x2100', 'issuer test', expiration, {from: issuer});

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

Expand Down Expand Up @@ -126,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('acceptRedemption Test', expiration, {from: issuer});
await campaign.issue('0x2100', 'acceptRedemption Test', expiration, {from: issuer});

// call acquire with auth message and issuer signature
const auth1 = create_auth_hash('acceptAcquisition', campaign.address, bearer)
Expand Down

0 comments on commit aeba4ae

Please sign in to comment.