Skip to content

Commit

Permalink
added total credits minted and burned
Browse files Browse the repository at this point in the history
  • Loading branch information
enderNakamoto committed Dec 17, 2024
1 parent e816e9d commit 5c1513e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ contract Controller is Ownable (msg.sender) {
uint256 public constant MILES_PER_CREDIT = 100;
uint256 public creditPrice;
uint256 public lastPriceUpdate;
uint256 public totalCreditsMinted;
uint256 public totalCreditsBurned;
address public priceOracle;

mapping(address => uint256) public creditBalance;
Expand Down Expand Up @@ -49,6 +51,9 @@ contract Controller is Ownable (msg.sender) {

creditPrice = 100 * 10**6; // Initial price 100 USDC
lastPriceUpdate = block.timestamp;

totalCreditsMinted = 0;
totalCreditsBurned = 0;
}

modifier onlyPriceOracle() {
Expand Down Expand Up @@ -106,7 +111,9 @@ contract Controller is Ownable (msg.sender) {

creditBalance[driver] += creditsEarned;
creditsMinted[driver] += creditsEarned;


totalCreditsMinted += creditsEarned;

uint256 milesDriven = roundedCurrentReading - vehicleInfo.lastProcessedOdometer;
emit CreditMinted(driver, creditsEarned, vin, milesDriven);
}
Expand All @@ -131,6 +138,7 @@ contract Controller is Ownable (msg.sender) {
emit CreditBurned(msg.sender, seller, 1);
}

totalCreditsBurned += amount;
creditBalance[msg.sender] += amount;
}

Expand Down
7 changes: 7 additions & 0 deletions test/CarbonIntegrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ contract CarbonIntegrationTest is Test {
function test_CompleteFlow() public {
// Step 2: Process odometer readings - Add Queue verification
vm.startPrank(owner);

assertEq(controller.totalCreditsMinted(), 0, "Total credits minted should be 0");
assertEq(controller.totalCreditsBurned(), 0, "Total credits burned should be 0");

// Tesla1 drives 350 miles (3 credits)
controller.registerVehicle(tesla1, "TESLA2023_1");
Expand Down Expand Up @@ -99,5 +102,9 @@ contract CarbonIntegrationTest is Test {
tesla2InitialBalance + (1 * 100 * 10**6),
"Tesla2 should have received 100 USDC"
);

// Verify total credits minted and burned
assertEq(controller.totalCreditsMinted(), 5, "Total credits minted should be 5");
assertEq(controller.totalCreditsBurned(), 4, "Total credits burned should be 4");
}
}

0 comments on commit 5c1513e

Please sign in to comment.