diff --git a/contracts/RGETokenInterface.sol b/contracts/RGETokenInterface.sol index ba59008..397e387 100644 --- a/contracts/RGETokenInterface.sol +++ b/contracts/RGETokenInterface.sol @@ -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); diff --git a/contracts/RougeFactory.sol b/contracts/RougeFactory.sol index e9e8918..d82ab01 100644 --- a/contracts/RougeFactory.sol +++ b/contracts/RougeFactory.sol @@ -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... diff --git a/contracts/SimpleRougeCampaign.sol b/contracts/SimpleRougeCampaign.sol index a546ab6..e62a409 100644 --- a/contracts/SimpleRougeCampaign.sol +++ b/contracts/SimpleRougeCampaign.sol @@ -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); @@ -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); @@ -64,7 +67,10 @@ contract SimpleRougeCampaign { campaignIssued = true; campaignExpiration = _campaignExpiration; available = issuance; - + scheme = _scheme; + + emit Issuance(_scheme, _name, _campaignExpiration); + } modifier CampaignOpen() { diff --git a/test/RougeFactory.js b/test/RougeFactory.js index d59794c..09aaf26 100644 --- a/test/RougeFactory.js +++ b/test/RougeFactory.js @@ -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) { @@ -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"); diff --git a/test/SimpleRougeCampaign.js b/test/SimpleRougeCampaign.js index 597c866..8e7e3b6 100644 --- a/test/SimpleRougeCampaign.js +++ b/test/SimpleRougeCampaign.js @@ -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) { @@ -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); @@ -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"); @@ -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}); @@ -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)