Skip to content

Instantly share code, notes, and snippets.

@nfet
Last active May 28, 2021 20:50
Show Gist options
  • Save nfet/d4a653e9dd86018862911e86c57570c4 to your computer and use it in GitHub Desktop.
Save nfet/d4a653e9dd86018862911e86c57570c4 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.1+commit.c8a2cb62.js&optimize=false&gist=

Overview

The following loyalty contracts written in solidty is an example of a User-owned loyalty points (1 ETH Address per loyalty member).

pragma solidity >=0.4.22 <=0.8.4;
contract LoyaltyContract {
address public owner;
/*
* This creates an array with all balances
* key - loyaltyOwnerId (An external system id that owns the earned points)
* value - The amount of loyalty points
*/
mapping (uint256 => uint256) public balanceOf;
constructor() {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) onlyOwner public {
owner = newOwner;
}
}
contract ChaseLoyaltyContract is LoyaltyContract {
constructor() {}
function earnPoints(uint256 _loyaltyOwnerId, uint256 _value) onlyOwner payable public returns (bool success) {
require(balanceOf[_loyaltyOwnerId] + _value >= balanceOf[_loyaltyOwnerId]); // Check for overflows
balanceOf[_loyaltyOwnerId] += _value;
return true;
}
function burnPoints(uint256 _loyaltyOwnerId, uint256 _value) onlyOwner payable public returns (bool success) {
require(balanceOf[_loyaltyOwnerId] + _value >= balanceOf[_loyaltyOwnerId]); // Check for overflows
balanceOf[_loyaltyOwnerId] -= _value;
return true;
}
}
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "./loyalty.sol";
contract test3 {
ChaseLoyaltyToken token;
function beforeAll () public {
token = new ChaseLoyaltyToken(2);
}
function checkWinningProposal () public {
token.burnPoints(1);
//Assert.equal(token.balanceOf[token.owner], uint(1), "1 should be the winning proposal");
}
function checkWinninProposalWithReturnValue () public view returns (bool) {
return token.balanceOf(address(token.owner)) == uint256(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment