Skip to content

Commit

Permalink
feat: add project data
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffprestes committed Nov 21, 2024
1 parent 549b257 commit e453444
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cache/solidity-files-cache.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cache/test-failures
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_SetDataTwice
29 changes: 25 additions & 4 deletions script/CarbonProjectDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,30 @@ contract CarbonProjectDeployScript is Script {

function run() public {
vm.startBroadcast();

cp = new CarbonProject("https://www.neocarbon.com.br/br/registro/projeto?id={id}");

address owner = address(0x7aC722a69CDb106127f1f2cC86761B28176E5379);
cp = new CarbonProject("https://www.neocarbon.com.br/br/registro/projeto?id={id}", owner);
vm.stopBroadcast();
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
bool executed = cp.setProjectData(
4561,
"MTALT20230003",
"AGROPECUARIA J L LTDA",
"Unidade de Carbono Florestal - ARR + REDD",
"Alto Taquari/MT/BRA",
"Registrado",
1691971200,
1723593600,
315360000,
"2102.83 hectares");
require(executed, "Failed to set project data");

}
}

}

/*
forge script script/CarbonProjectDeployScript.s.sol:CarbonProjectDeployScript --rpc-url $RPC_POLYGON_MAINNET --broadcast --verify --chain polygon --etherscan-api-key $POLYGONSCAN_API_KEY -vvvv
forge script script/CarbonProjectDeployScript.s.sol:CarbonProjectDeployScript --rpc-url $RPC_POLYGON_TEST --broadcast --verify --chain polygon --etherscan-api-key $POLYGONSCAN_API_KEY -vvvv
forge script script/CarbonProjectDeployScript.s.sol:CarbonProjectDeployScript --rpc-url %RPC_POLYGON_TEST% --broadcast --verify --chain polygon --etherscan-api-key %POLYGONSCAN_API_KEY% -vvvv
*/
50 changes: 48 additions & 2 deletions src/CarbonProject.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
pragma solidity 0.8.25;

import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract CarbonProject is ERC1155 {
contract CarbonProject is ERC1155, Ownable {

bool public _projectDataSet;
uint256 public _id;
string public _nameNumber;
string public _proposer;
Expand All @@ -16,8 +18,52 @@ contract CarbonProject is ERC1155 {
uint256 public _period;
string public _areaSize;

constructor(string memory uri_) ERC1155(uri_) {
constructor(string memory uri_, address owner_) ERC1155(uri_) Ownable(owner_) {
_setURI(uri_);
_projectDataSet = false;
}

function setProjectData(
uint256 id,
string memory nameNumber,
string memory proposer,
string memory activity,
string memory location,
string memory status,
uint256 startDate,
uint256 endDate,
uint256 period,
string memory areaSize
) public onlyOwner returns (bool) {
require(!_projectDataSet, "Project data already set");
_id = id;
_nameNumber = nameNumber;
_proposer = proposer;
_activity = activity;
_location = location;
_status = status;
_startDate = startDate;
_endDate = endDate;
_period = period;
_areaSize = areaSize;
_projectDataSet = true;
return true;
}

function getProjectData() public view returns (
uint256 id,
string memory nameNumber,
string memory proposer,
string memory activity,
string memory location,
string memory status,
uint256 startDate,
uint256 endDate,
uint256 period,
string memory areaSize,
bool projectDataSet
) {
return (_id, _nameNumber, _proposer, _activity, _location, _status, _startDate, _endDate, _period, _areaSize, projectDataSet);
}

}
62 changes: 61 additions & 1 deletion test/CarbonProject.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,76 @@ import {Test, console} from "forge-std/Test.sol";

contract CarbonProjectTest is Test {
string public uri = "https://www.neocarbon.com.br/br/registro/projeto?id={id}";
address public owner = address(0x123);

CarbonProject public carbonProject;

function setUp() public {
carbonProject = new CarbonProject(uri);
carbonProject = new CarbonProject(uri, owner);
}

function test_CarbonProject() public view {
console.log("CarbonProject: ", address(carbonProject));
console.log("URI: ", carbonProject.uri(5451));
console.log("Owner: ", carbonProject.owner());
assertEq(carbonProject.uri(5451), uri);
assertEq(carbonProject.owner(), owner);
}

function testFail_SetDataNotOwner() public {
setDataTest();
}

function test_SetData() public {
vm.prank(owner);
setDataTest();
(uint256 id,
string memory nameNumber,
string memory proposer,
string memory activity,
string memory location,
string memory status,
uint256 startDate,
uint256 endDate,
uint256 period,
string memory areaSize,
bool projectDataSet) = carbonProject.getProjectData();
console.log("Project Data: ", projectDataSet);
// assertEq(projectDataSet, true);
assertEq(id, 4561);
assertEq(nameNumber, "MTALT20230003");
assertEq(proposer, "AGROPECUARIA J L LTDA");
assertEq(activity, "Unidade de Carbono Florestal - ARR + REDD");
assertEq(location, "Alto Taquari/MT/BRA");
assertEq(status, "Registrado");
assertEq(startDate, 1691971200);
assertEq(endDate, 1723593600);
assertEq(period, 315360000);
assertEq(areaSize, "2102.83 hectares");
}

function testFail_SetDataTwice() public {
vm.prank(owner);
setDataTest();
vm.prank(owner);
setDataTest();
}

function setDataTest() public {
bool executed = carbonProject.setProjectData(
4561,
"MTALT20230003",
"AGROPECUARIA J L LTDA",
"Unidade de Carbono Florestal - ARR + REDD",
"Alto Taquari/MT/BRA",
"Registrado",
1691971200,
1723593600,
315360000,
"2102.83 hectares");

console.log("CarbonProject: ", address(carbonProject));
console.log("Executed setProjectData: ", executed);
assertEq(executed, true);
}
}

0 comments on commit e453444

Please sign in to comment.