diff --git a/catalyst/alt_data/__init__.py b/catalyst/marketplace/__init__.py similarity index 100% rename from catalyst/alt_data/__init__.py rename to catalyst/marketplace/__init__.py diff --git a/catalyst/alt_data/marketplace.py b/catalyst/marketplace/marketplace.py similarity index 100% rename from catalyst/alt_data/marketplace.py rename to catalyst/marketplace/marketplace.py diff --git a/etc/requirements_marketplace.txt b/etc/requirements_marketplace.txt new file mode 100644 index 00000000..cbb3a5a3 --- /dev/null +++ b/etc/requirements_marketplace.txt @@ -0,0 +1 @@ +web3==4.0.0b5 \ No newline at end of file diff --git a/marketplace/contracts/Marketplace.sol b/marketplace/contracts/Marketplace.sol new file mode 100644 index 00000000..54a14d1a --- /dev/null +++ b/marketplace/contracts/Marketplace.sol @@ -0,0 +1,19 @@ +pragma solidity ^0.4.17; + +contract Marketplace { + address[16] public subscribers; + + // Adopting a pet + function subscribe(uint dataSourceId) public returns (uint) { + require(dataSourceId >= 0 && dataSourceId <= 1); + + subscribers[dataSourceId] = msg.sender; + + return dataSourceId; + } + + // Retrieving the subscribers + function getSubscribers() public view returns (address[16]) { + return subscribers; + } +} \ No newline at end of file diff --git a/marketplace/contracts/Migrations.sol b/marketplace/contracts/Migrations.sol new file mode 100644 index 00000000..f170cb4f --- /dev/null +++ b/marketplace/contracts/Migrations.sol @@ -0,0 +1,23 @@ +pragma solidity ^0.4.17; + +contract Migrations { + address public owner; + uint public last_completed_migration; + + modifier restricted() { + if (msg.sender == owner) _; + } + + function Migrations() 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); + } +} diff --git a/marketplace/marketplace.iml b/marketplace/marketplace.iml new file mode 100644 index 00000000..cf4ef5ed --- /dev/null +++ b/marketplace/marketplace.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/marketplace/migrations/1_initial_migration.js b/marketplace/migrations/1_initial_migration.js new file mode 100644 index 00000000..4d5f3f9b --- /dev/null +++ b/marketplace/migrations/1_initial_migration.js @@ -0,0 +1,5 @@ +var Migrations = artifacts.require("./Migrations.sol"); + +module.exports = function(deployer) { + deployer.deploy(Migrations); +}; diff --git a/marketplace/migrations/2_deploy_contracts.js b/marketplace/migrations/2_deploy_contracts.js new file mode 100644 index 00000000..e3935400 --- /dev/null +++ b/marketplace/migrations/2_deploy_contracts.js @@ -0,0 +1,5 @@ +var Marketplace = artifacts.require ("Marketplace"); + +module.exports = function (deployer) { + deployer.deploy (Marketplace); +}; \ No newline at end of file diff --git a/marketplace/test/TestMarketplace.sol b/marketplace/test/TestMarketplace.sol new file mode 100644 index 00000000..ea1c7fb3 --- /dev/null +++ b/marketplace/test/TestMarketplace.sol @@ -0,0 +1,39 @@ +pragma solidity ^0.4.17; + +import "truffle/Assert.sol"; +import "truffle/DeployedAddresses.sol"; +import "../contracts/Marketplace.sol"; + +contract TestMarketplace { + Marketplace marketplace = Marketplace(DeployedAddresses.Marketplace()); + + // Testing the adopt() function + function testUserCanSubscribe() public { + uint returnedId = marketplace.subscribe(0); + + uint expected = 0; + + Assert.equal(returnedId, expected, "Adoption of pet ID 8 should be recorded."); + } + + // Testing retrieval of a single pet's owner + function testGetSubscriberAddressByDataSourceId() public { + // Expected owner is this contract + address expected = this; + + address adopter = marketplace.subscribers(0); + + Assert.equal(adopter, expected, "Owner of data source ID 0 should be recorded."); + } + + // Testing retrieval of all pet owners + function testGetSubscriberAddressByDataSourceIdInArray() public { + // Expected owner is this contract + address expected = this; + + // Store adopters in memory rather than contract's storage + address[16] memory subscribers = marketplace.getSubscribers(); + + Assert.equal(subscribers[0], expected, "Owner of pet ID 0 should be recorded."); + } +} \ No newline at end of file diff --git a/marketplace/truffle-config.js b/marketplace/truffle-config.js new file mode 100644 index 00000000..a6330d6d --- /dev/null +++ b/marketplace/truffle-config.js @@ -0,0 +1,4 @@ +module.exports = { + // See + // to customize your Truffle configuration! +}; diff --git a/marketplace/truffle.js b/marketplace/truffle.js new file mode 100644 index 00000000..67f2dd44 --- /dev/null +++ b/marketplace/truffle.js @@ -0,0 +1,11 @@ +module.exports = { + // See + // to customize your Truffle configuration! + networks: { + development: { + host: "localhost", + port: 7545, + network_id: "*" // Match any network id + } + } +};