mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-27 17:47:56 +08:00
BLD: first test of the marketplace smart contract
This commit is contained in:
@@ -0,0 +1 @@
|
||||
web3==4.0.0b5
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="Python" name="Python">
|
||||
<configuration sdkName="Python 3.6.3 virtualenv at ~/Code/enigma/catalyst/python3" />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Python 3.6.3 virtualenv at ~/Code/enigma/catalyst/python3 interpreter library" level="application" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,5 @@
|
||||
var Migrations = artifacts.require("./Migrations.sol");
|
||||
|
||||
module.exports = function(deployer) {
|
||||
deployer.deploy(Migrations);
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
var Marketplace = artifacts.require ("Marketplace");
|
||||
|
||||
module.exports = function (deployer) {
|
||||
deployer.deploy (Marketplace);
|
||||
};
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
// See <http://truffleframework.com/docs/advanced/configuration>
|
||||
// to customize your Truffle configuration!
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
// See <http://truffleframework.com/docs/advanced/configuration>
|
||||
// to customize your Truffle configuration!
|
||||
networks: {
|
||||
development: {
|
||||
host: "localhost",
|
||||
port: 7545,
|
||||
network_id: "*" // Match any network id
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user