Commit 43cd466e authored by vicotor's avatar vicotor

add upgrade test code

parent bf959dc3
{addr: "0x452B05527F70bE30e16D01610C57E40c8ced54C6", name:"UserLogin"},
{addr: "0xD5e6035CE7371d0C0664A4d152788D8411F71fe7", name:"Constant"},
{addr: "0x913E224a67d160501744BeFc7fd279D228932b9B", name:"MetaToken"},
{addr: "0xb3842FEff99fC9dE995dE4FE81D9987654cdbf6D", name:"RaceToken"},
{addr: "0x4CB47128B01E15eb0aa0D2BC41a1c77CA3BF0654", name:"UsdtToken"},
{addr: "0xa849f84Bf38175D618d3495310672E5DFfFd6D24", name:"Coin"},
{addr: "0xBdFCeb5D19aa916a6CfdD6987D4c102700609Fc0", name:"EquipToken"},
{addr: "0xEEDb4FbC408E2C769BcEd2f89BcCb5E710E6842c", name:"HorseToken"},
{addr: "0x1e2B567dC82531c71057928D44944EF03Ba0BE46", name:"ArenaToken"},
{addr: "0x92dC3A31960E920f00B526bEc4594CCF13D244BF", name:"Coin721"},
{addr: "0xefB856A4A8fA069F60a41a2237a1eA4482FE7d4d", name:"NFTMysteryBoxOffering"},
{addr: "0xfd441677247Dd2961Bba8F46b4bb3D6598E172A3", name:"Random"},
{addr: "0xE32902791FCC89047465392600af7CF08073DdA5", name:"Whitelist"},
{addr: "0xD9e4fAa4C31694FcdFcfa2eDE8C3Ae7D25F28AB6", name:"MysteryBox"},
{addr: "0xb6b8A39137958B8DCd3A34E24A2E44787bc22bAF", name:"MysteryData"},
{addr: "0x196e5719F7983F8749A23B5142f7308f4196f6C3", name:"RaceBonusDistribute"},
{addr: "0x6e0bBb19021E290eCA0366D14c9FcC66DB1E15f2", name:"RaceBonusPool"},
{addr: "0x4f99c25aCA0d56Cf2E8E36D7e83C9a4329c5FB01", name:"RaceBonusData"},
{addr: "0xeE60AB31Da5f991D89D8918e2c1a784EEDe41f7f", name:"RaceNFTAttr"},
{addr: "0x897aF09d81d347BC4940E58157B672EdBC7Fa3Dd", name:"EquipAttr"},
{addr: "0xe40B9C2CAC590a45e666545862aA59a050f5C498", name:"ArenaAttr"},
{addr: "0x2bA3BD1bE12a696A5da58EF434d0Fa47B2bE4F5D", name:"RaceAttr1"},
{addr: "0x7Fe9395130Db10cB7B1c547632602F6d5608d72b", name:"RaceAttr1_1"},
{addr: "0x2d15B840CE5De85931d915003af44B29a78ae16D", name:"RaceAttr2"},
{addr: "0xC7B7b222cB8E12EF1B73123732b3aFA94FE5b835", name:"RaceAttr2_1"},
{addr: "0x147612b0E32B7Be28C32375A85B98A6b0FaF8d34", name:"HorseCourseAttr"},
{addr: "0xC8574F717bc5C5A9B029eAd3Da669E745E101542", name:"HorseCourseAttrOpera"},
{addr: "0x617a061015fdF830A1F5637469a51fb4879F0ddd", name:"Bytes"},
{addr: "0x3BCC634C43c15971623d5E33475b1732553440b9", name:"EquipExtra"},
{addr: "0x6bE51BD56aabAC86A8b0E62F7e23f2Aa49Bc92ac", name:"RaceExtra"},
{addr: "0x1C961B7373a5cF966F45Ab9Ad493C405943b3e3a", name:"RaceExtra1"},
{addr: "0xdb6e69467083fbe6AAE0dff0823353Ce82c8c35f", name:"RaceExtra2"},
{addr: "0x83c812Cd6e4ea911a9628bcDEBc48c079C92dC68", name:"ArenaExtra"},
{addr: "0xd1933659411d0Fe803f6eC24F6b47627210C5Db0", name:"ArenaExtra1"},
{addr: "0x5A952fbb82E3c1238d9692126A77002675A1D80f", name:"ArenaExtra2"},
{addr: "0x82a947F3D70C86E8Fc01d70414650fA29d9578d4", name:"ArenaExtra3"}
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
contract Box {
uint256 private value;
// Emitted when the stored value changes
event ValueChanged(uint256 newValue);
// Stores a new value in the contract
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}
// Reads the last stored value
function retrieve() public view returns (uint256) {
return value;
}
}
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
contract BoxV2 {
uint256 private value;
// Emitted when the stored value changes
event ValueChanged(uint256 newValue);
// Stores a new value in the contract
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}
// Reads the last stored value
function retrieve() public view returns (uint256) {
return value;
}
function increment() public {
value = value + 1;
emit ValueChanged(value);
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;
// Uncomment this line to use console.log
// import "hardhat/console.sol";
contract Lock {
uint public unlockTime;
address payable public owner;
event Withdrawal(uint amount, uint when);
constructor(uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);
unlockTime = _unlockTime;
owner = payable(msg.sender);
}
function withdraw() public {
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
require(block.timestamp >= unlockTime, "You can't withdraw yet");
require(msg.sender == owner, "You aren't the owner");
emit Withdrawal(address(this).balance, block.timestamp);
owner.transfer(address(this).balance);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/utils/Address.sol";
import "../game/Auth.sol";
interface IERC721Token {
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(address from, address to, uint256 tokenId) external;
function transferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
contract Coin721V2 is Program {
mapping(address => address) public addressOf;
mapping(address => bool) private minters;
function initialize() public initializer {
program_initialize();
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyMiner() {
require(minters[msg.sender], "!miner");
_;
}
function addMinter(address _minter) public onlyOwner {
minters[_minter] = true;
}
function removeMinter(address _minter) public onlyOwner {
minters[_minter] = false;
}
/**
* @dev Add supported token addresses
*/
function add(address[] memory _address) public onlyAdmin returns (bool) {
require(_address.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _address.length; i++) {
addressOf[_address[i]] = _address[i];
}
return true;
}
/**
* @dev Del supported addresses
*/
function del(address[] memory _coins) public onlyAdmin returns (bool) {
require(_coins.length > 0 && _coins.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _coins.length; i++) {
delete addressOf[_coins[i]];
}
return true;
}
/**
* @dev Safe transfer from 'from' account to 'to' account
*/
function safeTransferFrom(address token, address from, address to, uint256 tokenId) public onlyMiner {
require(addressOf[token] != address(0), "Not supported coin!");
IERC721Token(addressOf[token]).safeTransferFrom(from, to, tokenId);
}
function balanceOf(address token, address account) public view returns (uint256){
require(addressOf[token] != address(0), "Not supported coin!");
uint256 balance = IERC721Token(addressOf[token]).balanceOf(account);
return balance;
}
function ownerOf(address token, uint256 tokenId) public view returns (address) {
require(addressOf[token] != address(0), "Not supported coin!");
address owner = IERC721Token(addressOf[token]).ownerOf(tokenId);
return owner;
}
function onERC721Received(address, address, uint256, bytes calldata) external pure returns(bytes4) {
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/utils/Address.sol";
import "../game/Auth.sol";
interface IERC20Token {
function decimals() external view returns (uint);
function totalSupply() external view returns (uint);
function balanceOf(address account) external view returns (uint);
function transfer(address recipient, uint amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint amount) external returns (bool);
function transferFrom(address sender, address recipient, uint amount) external returns (bool);
}
library SafeERC20Token {
using Address for address;
function safeTransfer(IERC20Token token, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20Token token, address from, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function callOptionalReturn(IERC20Token token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.
// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.
// solhint-disable-next-line max-line-length
// require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) {// Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
contract CoinV2 is Program {
using SafeERC20Token for IERC20Token;
mapping(uint256 => uint256) public priceOf;
mapping(uint256 => address) public addressOf;
mapping(address => bool) private minters;
function initialize() public initializer {
program_initialize();
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyMiner() {
require(minters[msg.sender], "!miner");
_;
}
function addMinter(address _minter) public onlyOwner {
minters[_minter] = true;
}
function removeMinter(address _minter) public onlyOwner {
minters[_minter] = false;
}
/**
* @dev Add supported token symbols, addresses and prices
*/
function add(uint256[] memory _coins, address[] memory _address, uint256[] memory _price) public onlyAdmin returns (bool) {
require(_coins.length == _address.length && _coins.length == _price.length && _coins.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _coins.length; i++) {
uint256 coin = _coins[i];
addressOf[coin] = _address[i];
priceOf[coin] = _price[i];
}
return true;
}
/**
* @dev Del supported token symbols, addresses and prices
*/
function del(uint256[] memory _coins) public onlyAdmin returns (bool) {
require(_coins.length > 0 && _coins.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _coins.length; i++) {
uint256 coin = _coins[i];
delete priceOf[coin];
delete addressOf[coin];
}
return true;
}
/**
* @dev update token prices
*/
function setPrice(uint256[] memory _coins, uint256[] memory _price) public onlyProgram returns (bool) {
require(_coins.length == _price.length && _coins.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _coins.length; i++) {
uint256 coin = _coins[i];
if (_price[i] != 0 && priceOf[coin] != 0) {
priceOf[coin] = _price[i];
}
}
return true;
}
/**
* @dev Price conversion
*/
function convert(uint256 _coinName, uint256 _usdAmount) public view returns (uint256) {
uint256 _decimals = 10 ** IERC20Token(addressOf[_coinName]).decimals();
return _decimals * _usdAmount / priceOf[_coinName];
}
function convert1(uint256 _coinName, uint256 _usdAmount) public view returns (uint256) {
uint256 _decimals = 10 ** IERC20Token(addressOf[_coinName]).decimals();
return _decimals * _usdAmount;
}
/**
* @dev Safe transfer from 'from' account to 'to' account
*/
function safeTransferFrom(uint256 _coinName, address from, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransferFrom(from, to, convert(_coinName, value));
}
function safeTransferFrom1(uint256 _coinName, address from, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransferFrom(from, to, convert1(_coinName, value));
}
/**
* @dev Safe transfer from 'this' account to 'to' account
*/
function safeTransfer(uint256 _coinName, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransfer(to, convert(_coinName, value));
}
function safeTransfer1(uint256 _coinName, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransfer(to, convert1(_coinName, value));
}
function safeTransferWei(uint256 _coinName, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransfer(to, value);
}
function balanceOf(uint256 _coinName, address account) public view returns (uint256){
require(addressOf[_coinName] != address(0), "Not supported coin!");
uint256 balance = IERC20Token(addressOf[_coinName]).balanceOf(account);
return balance;
}
function decimals(uint256 _coinName) public view returns (uint) {
require(addressOf[_coinName] != address(0), "Not supported coin!");
uint d = IERC20Token(addressOf[_coinName]).decimals();
return d;
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../library/Bytes.sol";
import "../game/Auth.sol";
import "../Interface/BaseInterface.sol";
contract ERC721AttrV2 is Program {
using Bytes for bytes;
IERC721Token private tokenAddress;
// key => field => value.
// Record the fields and values corresponding to each contract
mapping(address => mapping(uint256 => mapping(string => bytes))) private values;
// field => types.
// Define fields and types
mapping(address => mapping(string => uint256)) private fieldsType;
// field => auth.
// Define the modification permissions of the field.
// 1 =>onlyAdmin, 2 => onlyProgram, 3 => owner
mapping(address => mapping(string => uint256)) private fieldsAuth;
// field => value => true.
// Record has only required fields
mapping(address => mapping(string => mapping(bytes => bool))) private uniques;
// 记录数组。
// tokenId ===> field ===> 索引
mapping(uint256 => mapping(string => uint256)) private index;
// tokenId ===> field ===> 索引 ===> 值
mapping(uint256 => mapping(string => mapping(uint256 => bytes))) private arrayValue;
modifier checkAuth(string memory fields, address addr, uint256 tokenId) {
uint256 auth = fieldsAuth[addr][fields];
if (auth == 1) {
require(isAdmin(msg.sender), "only admin");
} else if (auth == 2) {
require(isProgram(msg.sender), "only program");
} else if (auth == 3) {
tokenAddress = IERC721Token(addr);
require(tokenAddress.ownerOf(tokenId) == msg.sender, "only owner");
} else if (auth == 0) {
require(false, "Invalid field");
}
_;
}
function initialize() public initializer {
program_initialize();
}
// 初始化参数,参数名称、参数类型、参数修改权限(1 admin,2 program,3 拥有者)
function setFiled(address addr, string[] memory field, uint256[] memory types, uint256[] memory auth) public onlyAdmin returns (bool) {
require(field.length > 0 && field.length <= 256, "Invalid parameters");
require(field.length == types.length && field.length == auth.length, "Invalid parameters");
for (uint256 i = 0; i < field.length; i++) {
bool result = _setFiled(addr, field[i], types[i], auth[i]);
require(result, "setFiled error");
}
return true;
}
function setValues(address addr, uint256 tokenId, string memory field, bytes memory value) public checkAuth(field, addr, tokenId) returns (bool) {
bool result = _setValue(addr, tokenId, field, value);
return result;
}
function setUniques(address addr, string memory field, bytes memory value) public onlyProgram returns (bool) {
require(!uniques[addr][field][value], "Uniqueness verification failed");
bool result = _setUniques(addr, field, value, true);
return result;
}
function clearUniques(address addr, string memory field, bytes memory value) public onlyProgram returns (bool) {
require(uniques[addr][field][value], "Uniqueness verification failed");
bool result = _setUniques(addr, field, value, false);
delete uniques[addr][field][value];
return result;
}
function delFiled(address addr, string memory field) public onlyAdmin returns (bool) {
bool result = _delFiled(addr, field);
return result;
}
function delValues(address addr, uint256 tokenId, string memory field) public checkAuth(field, addr, tokenId) returns (bool) {
bool result = _delValue(addr, tokenId, field);
return result;
}
// function delUniques(address addr, string memory field) public onlyProgram returns (bool) {
// _delUniques(field);
// return true;
// }
function _setValue(address addr, uint256 tokenId, string memory field, bytes memory value) internal returns (bool){
values[addr][tokenId][field] = value;
return true;
}
function _setUniques(address addr, string memory field, bytes memory value, bool b) internal returns (bool){
uniques[addr][field][value] = b;
return true;
}
function _setFiled(address addr, string memory field, uint256 types, uint256 auth) internal returns (bool){
fieldsType[addr][field] = types;
fieldsAuth[addr][field] = auth;
return true;
}
function _delFiled(address addr, string memory field) internal returns (bool){
delete fieldsType[addr][field];
delete fieldsAuth[addr][field];
return true;
}
function _delValue(address addr, uint256 tokenId, string memory field) internal returns (bool){
delete values[addr][tokenId][field];
return true;
}
function getValue(address addr, uint256 tokenId, string memory field) public view returns (bytes memory result){
return values[addr][tokenId][field];
}
function getAuth(address addr, string memory field) public view returns (uint256){
return fieldsAuth[addr][field];
}
function getType(address addr, string memory field) public view returns (uint256){
return fieldsType[addr][field];
}
function getUniques(address addr, string memory field, bytes memory value) public view returns (bool){
return uniques[addr][field][value];
}
function setArrayValue(uint256 tokenId, string memory field, bytes memory value) public onlyProgram returns (bool){
uint256 count = index[tokenId][field];
arrayValue[tokenId][field][count] = value;
index[tokenId][field] = count + 1;
return true;
}
function delArrayValue(uint256 tokenId, string memory field) public onlyProgram returns (bool){
uint256 count = index[tokenId][field];
for (uint256 i = 0; i < count; i++) {
delete arrayValue[tokenId][field][i];
}
delete index[tokenId][field];
return true;
}
function removeArrayValue(uint256 tokenId, string memory field, bytes memory value) public onlyProgram returns (bool){
uint256 count = index[tokenId][field];
bool isOn;
for (uint256 i = 0; i < count; i++) {
if (keccak256(value) == keccak256(arrayValue[tokenId][field][i])) {
isOn = true;
continue;
}
if (isOn) {
bytes memory oldValue = arrayValue[tokenId][field][i];
arrayValue[tokenId][field][i - 1] = oldValue;
}
}
if (isOn) {
index[tokenId][field] = count - 1;
}
return true;
}
function checkArrayValue(uint256 tokenId, string memory field, bytes memory value) public view onlyProgram returns (bool){
uint256 count = index[tokenId][field];
for (uint256 i = 0; i < count; i++) {
if (keccak256(value) == keccak256(arrayValue[tokenId][field][i])) {
return true;
}
}
return false;
}
function getArrayValue(uint256 tokenId, string memory field) public view returns (uint256[] memory){
uint256 count = index[tokenId][field];
uint256[] memory arr = new uint256[](count);
for (uint256 i = 0; i < count; i++) {
bytes memory id = arrayValue[tokenId][field][i];
arr[i] = id.BytesToUint256();
}
return arr;
}
function getArrayCount(uint256 tokenId, string memory field) public view returns (uint256){
return index[tokenId][field];
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../Interface/IERC721Attr.sol";
import "../Interface/IERC721Token.sol";
import "../library/Bytes.sol";
import "../library/Uint256.sol";
import "../library/String.sol";
import "../library/Address.sol";
import "../game/Auth.sol";
contract HorseArenaAttrOperaContractV2 is Program {
using Uint256 for uint256;
using String for string;
using Address for address;
using Bytes for bytes;
IERC721Attr private _horseFactoryAttrAddress;
IERC721Token private _horseFactoryTokenAddress;
string public _name; //名称
string public _createTime; //创建日期
string public _ownerType; //类型
string public _isClose; // 是否关闭
string public _raceCount; //当天开赛次数,私人赛场每天有次数限制
string public _lastRaceTime; //最后一次开赛时间
string public _totalRaceCount; //总开赛次数
string public _mortAmount; //抵押金额
string public _gameId; //比赛的id
string public _horseIds; //比赛的id
modifier checkOwnerTypeValue(uint256 ownerType) {
if (ownerType == 0 || ownerType == 1) {
require(true, "Legal field value");
} else {
require(false, "Invalid field value");
}
_;
}
modifier checkAuth(uint256 tokenId) {
require(_horseFactoryTokenAddress.ownerOf(tokenId) == msg.sender, "only owner can do it!");
_;
}
function initialize() public initializer {
program_initialize();
_name = "name";//名称
_createTime = "createTime";//创建日期
_ownerType = "ownerType";//类型
_isClose = "isClose"; // 是否关闭
_raceCount = "raceCount";//当天开赛次数,私人赛场每天有次数限制
_lastRaceTime = "lastRaceTime";//最后一次开赛时间
_totalRaceCount = "totalRaceCount";//总开赛次数
_mortAmount = "mortAmount";//抵押金额
_gameId = "gameId";//比赛的id
_horseIds = "horseIds";//比赛的id
}
function init(address factoryAttrAddress, address factoryToken) public onlyAdmin returns (bool) {
_horseFactoryAttrAddress = IERC721Attr(factoryAttrAddress);
_horseFactoryTokenAddress = IERC721Token(factoryToken);
return true;
}
function setHorseFactName(uint256 tokenId, string memory name) public onlyProgram returns (bool) {
bytes memory nameBytes = name.StringToBytes();
bool boo = _horseFactoryAttrAddress.getUniques(address(_horseFactoryTokenAddress), _name, nameBytes);
require(!boo, "Name already used");
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _name, nameBytes);
_horseFactoryAttrAddress.setUniques(address(_horseFactoryTokenAddress), _name, nameBytes);
return result;
}
function setCreateTime(uint256 tokenId, uint256 time) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _createTime, time.Uint256ToBytes());
return result;
}
function setHorseFactTypes(uint256 tokenId, uint256 types) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _ownerType, types.Uint256ToBytes());
return result;
}
function setFactoryStatus(uint256 tokenId, uint256 status) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _isClose, status.Uint256ToBytes());
return result;
}
function setRaceCount(uint256 tokenId, uint256 count) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _raceCount, count.Uint256ToBytes());
return result;
}
function uptTotalRaceCount(uint256 tokenId, uint256 count) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _totalRaceCount, count.Uint256ToBytes());
return result;
}
function setLastRaceTime(uint256 tokenId, uint256 time) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _lastRaceTime, time.Uint256ToBytes());
return result;
}
function setMortAmount(uint256 tokenId, uint256 amount) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _mortAmount, amount.Uint256ToBytes());
return result;
}
function getFactoryName(uint256 tokenId) public view returns (string memory){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _name);
return bytesInfo.BytesToString();
}
function getCreateTime(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _createTime);
return bytesInfo.BytesToUint256();
}
function getOwnerType(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _ownerType);
return bytesInfo.BytesToUint256();
}
function getIsClose(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _isClose);
return bytesInfo.BytesToUint256();
}
function getRaceCount(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _raceCount);
return bytesInfo.BytesToUint256();
}
function getLastRaceTime(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _lastRaceTime);
return bytesInfo.BytesToUint256();
}
function getTotalRaceCount(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _totalRaceCount);
return bytesInfo.BytesToUint256();
}
function getMortAmount(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _mortAmount);
return bytesInfo.BytesToUint256();
}
function setGameId(uint256 tokenId, uint256 gameId) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setArrayValue(tokenId, _gameId, gameId.Uint256ToBytes());
return result;
}
function setHorseId(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setArrayValue(tokenId, _horseIds, horseId.Uint256ToBytes());
return result;
}
function checkGameId(uint256 tokenId, uint256 gameId) public view returns (bool){
bool result = _horseFactoryAttrAddress.checkArrayValue(tokenId, _gameId, gameId.Uint256ToBytes());
return result;
}
function checkGameIdIsExit(uint256 gameId) public view returns (bool){
bytes memory idBytes = gameId.Uint256ToBytes();
bool boo = _horseFactoryAttrAddress.getUniques(address(_horseFactoryTokenAddress), _gameId, idBytes);
return boo;
}
function setGameIdUniques(uint256 gameId) public onlyProgram returns (bool) {
bytes memory idBytes = gameId.Uint256ToBytes();
bool boo = _horseFactoryAttrAddress.setUniques(address(_horseFactoryTokenAddress), _gameId, idBytes);
return boo;
}
function clearGameIdUniques(uint256 gameId) public onlyProgram returns (bool) {
bytes memory idBytes = gameId.Uint256ToBytes();
bool boo = _horseFactoryAttrAddress.setUniques(address(_horseFactoryTokenAddress), _gameId, idBytes);
return boo;
}
function checkHorseId(uint256 tokenId, uint256 horseId) public view returns (bool){
bool result = _horseFactoryAttrAddress.checkArrayValue(tokenId, _horseIds, horseId.Uint256ToBytes());
return result;
}
function getHorseIdCount(uint256 tokenId) public view returns (uint256){
uint256 count = _horseFactoryAttrAddress.getArrayCount(tokenId, _horseIds);
return count;
}
function delHorseIdOne(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.removeArrayValue(tokenId, _horseIds, horseId.Uint256ToBytes());
return result;
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/utils/math/Math.sol";
import "../Interface/ICoin.sol";
import "../Interface/IConstant.sol";
import "../game/Auth.sol";
interface IHorseRaceOpera {
function setHorseStatusBatch(uint256[] calldata tokenId, uint256 status) external returns (bool);
function setHorseStatus(uint256 tokenId, uint256 status) external returns (bool);
function setRaceUpdateTime(uint256 tokenId, uint256 raceUpdateTime) external returns (bool);
function getBirthDay(uint256 tokenId) external returns (uint256);
function getHorseRaceStatus(uint256 tokenId) external returns (uint256);
function getRaceUpdateTime(uint256 tokenId) external returns (uint256);
function setRaceId(uint256 tokenId, uint256 raceId) external returns (bool);
function setRaceIdBatch(uint256[] calldata tokenIds, uint256 raceId) external returns (bool);
function setRaceType(uint256 tokenId, uint256 raceType) external returns (bool);
function setRacecourse(uint256 tokenId, uint256 racecourse) external returns (bool);
function setDistance(uint256 tokenId, uint256 distance) external returns (bool);
function getGrade(uint256 tokenId) external returns (uint256);
function getRacecourse(uint256 tokenId) external returns (uint256);
function checkStatus(uint256[] calldata tokenIds, uint256 status) external returns (bool);
function checkGameInfo(uint256[] calldata tokenIds, uint256 types, uint256 racecourseId,
uint256 level, uint256 distance) external returns (bool);
function getDistance(uint256 tokenId) external returns (uint256);
}
interface IERC721Token {
function ownerOf(uint256 tokenId) external view returns (address owner);
}
interface IRacecourseOpera {
function setHorseId(uint256 tokenId, uint256 horseId) external returns (bool);
function getHorseId(uint256 tokenId) external returns (uint256[] memory);
function delHorseId(uint256 tokenId) external returns (bool);
}
interface IArenaOpera {
function getIsClose(uint256 tokenId) external returns (uint256);
function checkGameIdIsExit(uint256 gameId) external returns (bool);
function setGameIdUniques(uint256 gameId) external returns (bool);
function getHorseIdCount(uint256 tokenId) external returns (uint256);
function setHorseId(uint256 tokenId, uint256 horseId) external returns (bool);
function delHorseIdOne(uint256 tokenId, uint256 horseId) external returns (bool);
function checkGameId(uint256 tokenId, uint256 gameId) external returns (bool);
function checkHorseId(uint256 tokenId, uint256 gameId) external returns (bool);
function getRaceCount(uint256 tokenId) external returns (uint256);
function getTotalRaceCount(uint256 tokenId) external returns (uint256);
function getLastRaceTime(uint256 tokenId) external returns (uint256);
function getOwnerType(uint256 tokenId) external returns (uint256);
function setRaceCount(uint256 tokenId, uint256 count) external returns (bool);
function setGameId(uint256 tokenId, uint256 gameId) external returns (bool);
function uptTotalRaceCount(uint256 tokenId, uint256 count) external returns (bool);
function setLastRaceTime(uint256 tokenId, uint256 time) external returns (bool);
}
contract HorseArenaExtra2V2 is Program {
using Math for uint256;
ICoin private _coin; // 抵押token合约地址
IArenaOpera private _opera;
IHorseRaceOpera private _horseOpera1_1;
IHorseRaceOpera private _horseOpera2;
IHorseRaceOpera private _horseOpera2_1;
IConstant private _constant; // 常量合约地址
IERC721Token private _horseTokenAddress;
event ApplyGame(address account, uint256 horseId, uint256 arenaId, uint256 raceType, uint256 distance,
uint256 time, uint256 status);
event CancelApplyGame(address account, uint256 horseId, uint256 status, uint256 time, uint256 arenaId, uint256 gameId,
uint256 raceType, uint256 distance);
event WeekScoreRank(uint256[] horseId, uint256[] totalScore, address[] accounts, uint256[] rank);
event MonthScoreRank(uint256[] horseId, uint256[] totalScore, address[] accounts, uint256[] rank);
event YearsScoreRank(uint256[] horseId, uint256[] totalScore, address[] accounts, uint256[] rank);
modifier checkAuth(uint256 tokenId) {
require(_horseTokenAddress.ownerOf(tokenId) == msg.sender, "only owner can do it!");
_;
}
function initialize() public initializer {
program_initialize();
}
function init(address operaAddr, address coinAddr, address horseTokenAddress,
address horseOpera1_1, address horseOpera2, address horseOpera2_1, address consAddr) public onlyAdmin returns (bool){
_opera = IArenaOpera(operaAddr);
_coin = ICoin(coinAddr);
_horseOpera1_1 = IHorseRaceOpera(horseOpera1_1);
_horseOpera2 = IHorseRaceOpera(horseOpera2);
_horseOpera2_1 = IHorseRaceOpera(horseOpera2_1);
_constant = IConstant(consAddr);
_horseTokenAddress = IERC721Token(horseTokenAddress);
return true;
}
// 报名比赛。
function applyGame(uint256 tokenId, uint256 horseId,
uint256 raceType, uint256 distance, uint256 level) public checkAuth(horseId) {
require(_opera.getIsClose(tokenId) == 1, "The stadium is closed");
require(_horseOpera2_1.getHorseRaceStatus(horseId) == _constant.getResting(), "Abnormal state");
require(_horseOpera2_1.getGrade(horseId) == level, "Level mismatch");
require(_opera.getHorseIdCount(tokenId) <= _constant.getMaxApplyCount(), "The maximum number of apply game is exceeded");
require(level == 999 ? distance == 1200 : true, "unmatched horselevel and distance");
// 成长时间
uint256 spacing = block.timestamp - (_horseOpera2.getBirthDay(horseId));
require(spacing > _constant.getMinMatureTime(), "Immature horses");
// 多次操作冷却时间
uint256 raceSpacing = block.timestamp - (_horseOpera2_1.getRaceUpdateTime(horseId));
require(raceSpacing > _constant.getMinRaceUptTime(), "Cooling time");
// 大奖赛需要报名费
if (level != 999) {
_coin.safeTransferFrom1(_constant.getApplyGameToken(), msg.sender, address(_coin), _constant.getApplyGameAmountByDistance(distance));
}
_opera.setHorseId(tokenId, horseId);
// 修改马匹状态为报名中,记录马匹报名信息
_horseOpera1_1.setHorseStatus(horseId, _constant.getSigning());
_horseOpera1_1.setRaceType(horseId, raceType);
_horseOpera1_1.setRacecourse(horseId, tokenId);
_horseOpera1_1.setDistance(horseId, distance);
_horseOpera1_1.setRaceUpdateTime(horseId, block.timestamp);
emit ApplyGame(msg.sender, horseId, tokenId, raceType, distance, block.timestamp, _constant.getSigning());
}
// 取消报名
function cancelApplyGame(uint256 horseId) public checkAuth(horseId) {
require(_horseOpera2_1.getHorseRaceStatus(horseId) == 3, "Abnormal state");
// 多次操作冷却时间
uint256 raceSpacing = block.timestamp - (_horseOpera2_1.getRaceUpdateTime(horseId));
require(raceSpacing > _constant.getMinRaceUptTime(), "Cooling time");
// 大奖赛需要退还报名费
uint256 level = _horseOpera2_1.getGrade(horseId);
if (level != 999) {
uint256 distance = _horseOpera2_1.getDistance(horseId);
_coin.safeTransfer1(_constant.getApplyGameToken(), msg.sender, _constant.getApplyGameAmountByDistance(distance));
}
// 修改马匹状态为休息中,记录马匹报名信息,逻辑删除
_opera.delHorseIdOne(_horseOpera2_1.getRacecourse(horseId), horseId);
_horseOpera1_1.setHorseStatus(horseId, _constant.getResting());
_horseOpera1_1.setRaceId(horseId, 0);
_horseOpera1_1.setRaceType(horseId, 0);
_horseOpera1_1.setRacecourse(horseId, 0);
_horseOpera1_1.setDistance(horseId, 0);
_horseOpera1_1.setRaceUpdateTime(horseId, block.timestamp);
emit CancelApplyGame(msg.sender, horseId, _constant.getResting(), block.timestamp, 0, 0, 0, 0);
}
function _check(uint256 tokenId, uint256[] memory horseId) internal {
for (uint256 i = 0; i < horseId.length; i++) {
require(_opera.checkHorseId(tokenId, horseId[i]), "Abnormal state");
}
}
function weekRank(
uint256[] memory horseIds,
uint256[] memory totalScores,
address[] memory accounts,
uint256[] memory rank) public onlyProgram {
require(horseIds.length == totalScores.length || horseIds.length == accounts.length ||
horseIds.length == rank.length, "The parameter length is inconsistent");
emit WeekScoreRank(horseIds, totalScores, accounts, rank);
}
function monthRank(
uint256[] memory horseIds,
uint256[] memory totalScores,
address[] memory accounts,
uint256[] memory rank) public onlyProgram {
require(horseIds.length == totalScores.length || horseIds.length == accounts.length ||
horseIds.length == rank.length, "The parameter length is inconsistent");
emit MonthScoreRank(horseIds, totalScores, accounts, rank);
}
function yearsRank(
uint256[] memory horseIds,
uint256[] memory totalScores,
address[] memory accounts,
uint256[] memory rank) public onlyProgram {
require(horseIds.length == totalScores.length || horseIds.length == accounts.length ||
horseIds.length == rank.length, "The parameter length is inconsistent");
emit YearsScoreRank(horseIds, totalScores, accounts, rank);
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
This diff is collapsed.
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/utils/math/Math.sol";
import "../Interface/IERC721Attr.sol";
import "../Interface/IERC721Token.sol";
import "../Interface/IConstant.sol";
import "../Interface/ICoin.sol";
import "../game/Auth.sol";
import "../library/Bytes.sol";
import "hardhat/console.sol";
interface IArenaOpera {
function setHorseFactName(uint256 tokenId, string calldata name) external returns (bool);
function setCreateTime(uint256 tokenId, uint256 time) external returns (bool);
function setHorseFactTypes(uint256 tokenId, uint256 types) external returns (bool);
function setFactoryStatus(uint256 tokenId, uint256 status) external returns (bool);
function setMortAmount(uint256 tokenId, uint256 amount) external returns (bool);
function getCreateTime(uint256 tokenId) external returns (uint256);
function getMortAmount(uint256 tokenId) external returns (uint256);
}
contract HorseArenaContractV2 is Program {
using Math for uint256;
using Bytes for bytes;
ICoin private _coin; // 抵押token合约地址
IArenaOpera private _opera;
IERC721Token private _arenaTokenAddress;
IConstant private _constant; // 常量合约地址
event MintArena(address account, uint256 tokenId, uint256 time, uint256 types, uint256 mortAmount, string name, uint256 status);
event CloseArena(address account, uint256 tokenId, uint256 time, uint256 mortAmount, uint256 status);
event ArenaTransfer(address from, address to, uint256 tokenId, uint256 time);
modifier checkAuth(uint256 tokenId) {
require(_arenaTokenAddress.ownerOf(tokenId) == msg.sender, "only owner can do it!");
_;
}
modifier senderIsToken() {
require(msg.sender == address(_arenaTokenAddress), "only token contract can do it");
_;
}
function initialize() public initializer {
program_initialize();
}
function init(address operaAddr, address tokenAddr, address coinAddr, address consAddr) public onlyAdmin returns (bool){
_opera = IArenaOpera(operaAddr);
_arenaTokenAddress = IERC721Token(tokenAddr);
_coin = ICoin(coinAddr);
_constant = IConstant(consAddr);
return true;
}
// 生成马场:type : 0 官方的, 1 私人的
function _mintArena(string memory name, bytes memory sign, uint256 types) internal returns (uint256) {
require(sign.Decode(name) == _constant.getAccount(), "Signature verification failure");
require(types == 0 || types == 1, "invalid arena type");
_coin.safeTransferFrom1(_constant.getMortToken(), msg.sender, address(_coin), _constant.getMortAmount());
uint256 tokenId = _arenaTokenAddress.mint(msg.sender);
_opera.setHorseFactName(tokenId, name);
_opera.setCreateTime(tokenId, block.timestamp);
_opera.setHorseFactTypes(tokenId, types);
_opera.setFactoryStatus(tokenId, 1);
_opera.setMortAmount(tokenId, _constant.getMortAmount());
emit MintArena(msg.sender, tokenId, block.timestamp, types, _constant.getMortAmount(), name, 1);
return tokenId;
}
function mintOfficialArena(string memory name, bytes memory sign) public onlyAdmin() {
_mintArena(name, sign, 0);
}
// 抵押增发赛场
function mintArena(string memory name, bytes memory sign) public returns (uint256) {
return _mintArena(name, sign, 1);
}
// 关闭赛场
function closeArena(uint256 tokenId) public checkAuth(tokenId) returns (bool) {
uint256 current = block.timestamp;
uint256 spacing = current - (_opera.getCreateTime(tokenId));
require(spacing > _constant.getMinMortTime(), "Must not be less than the minimum mortgage time");
uint256 mortAmount = _opera.getMortAmount(tokenId);
_coin.safeTransfer1(_constant.getMortToken(), msg.sender, mortAmount);
_opera.setFactoryStatus(tokenId, 2);
_arenaTokenAddress.safeTransferFrom(msg.sender, address(_arenaTokenAddress), tokenId);
emit CloseArena(msg.sender, tokenId, block.timestamp, mortAmount, 2);
return true;
}
function beforeTransfer(address from, address to, uint256) public view senderIsToken returns (bool) {
// no need more handler.
if (_constant.isOfficialContract(from) || _constant.isOfficialContract(to)) {
//console.log("no need handler for arena extra contract transfer");
} else {
// nothing to do.
}
return true;
}
function afterTransfer(address from, address to, uint256 tokenId) public senderIsToken returns (bool) {
if (_constant.isOfficialContract(from) || _constant.isOfficialContract(to)) {
//console.log("no need handler for arena extra contract transfer");
} else {
console.log("emit event arenatransfer");
emit ArenaTransfer(from, to, tokenId,block.timestamp);
}
return true;
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../Interface/IERC721Attr.sol";
import "../Interface/IERC721Token.sol";
import "../library/Bytes.sol";
import "../library/Uint256.sol";
import "../library/String.sol";
import "../library/Address.sol";
import "../game/Auth.sol";
contract HorseEquipAttrOperaContractV2 is Program {
using Uint256 for uint256;
using String for string;
using Address for address;
using Bytes for bytes;
IERC721Attr private _horseEquipAttrAddress;
IERC721Token private _horseEquipTokenAddress;
string public _horseEquipTypes;
string public _horseEquipStyle;
string public _horseEquipStatus;
string public _horseEquipPrice; // 出售价格
string public _horseEquipOfUid;
string public _horseEquipOfHorseId;
string public _horseEquipDiscount;
string public _horseEquipReward;
string public _horseEquipCoin;
string public _horseEquipLastOwner; // 最后一次操作者
string public _horseEquipLastPrice; // 最后一次成交价格
string public _lastOperaTime; // 最后操作时间
modifier checkEquipTypesValue(uint256 equip_types) {
if (equip_types == 1 || equip_types == 2 || equip_types == 3 || equip_types == 4) {
require(true, "Legal field value");
} else {
require(false, "Invalid field value");
}
_;
}
modifier checkEquipStyleValue(uint256 equip_style) {
if (equip_style == 1 || equip_style == 2 || equip_style == 3 || equip_style == 4 || equip_style == 5) {
require(true, "Legal field value");
} else {
require(false, "Invalid field value");
}
_;
}
modifier checkSellAuth(uint256 tokenId) {
require(_horseEquipTokenAddress.ownerOf(tokenId) == msg.sender, "only owner can do it!");
_;
}
function initialize() public initializer {
program_initialize();
_horseEquipTypes = "horseEquipTypes";
_horseEquipStyle = "horseEquipStyle";
_horseEquipStatus = "horseEquipStatus";
_horseEquipPrice = "horseEquipPrice"; // 出售价格
_horseEquipOfUid = "horseEquipOfUid";
_horseEquipOfHorseId = "horseEquipOfHorseId";
_horseEquipDiscount = "horseEquipDiscount";
_horseEquipReward = "horseEquipReward";
_horseEquipCoin = "horseEquipCoin";
_horseEquipLastOwner = "horseEquipLastOwner"; // 最后一次操作者
_horseEquipLastPrice = "horseEquipLastPrice"; // 最后一次成交价格
_lastOperaTime = "lastOperaTime"; // 最后操作时间
}
function init(address equipAttrAddress, address horseEquipToken) public onlyAdmin returns (bool) {
_horseEquipAttrAddress = IERC721Attr(equipAttrAddress);
_horseEquipTokenAddress = IERC721Token(horseEquipToken);
return true;
}
function setEquipStatus(uint256 tokenId, uint256 status) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipStatus, status.Uint256ToBytes());
return result;
}
function setEquipStatusBatch(uint256[] memory tokenIds, uint256 status) public onlyProgram returns (bool) {
require(tokenIds.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < tokenIds.length; i++) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenIds[i], _horseEquipStatus, status.Uint256ToBytes());
require(result, "setEquipStatus error");
}
return true;
}
function setEquipTypes(uint256 tokenId, uint256 types) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipTypes, types.Uint256ToBytes());
return result;
}
function setEquipStyle(uint256 tokenId, uint256 style) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipStyle, style.Uint256ToBytes());
return result;
}
function setEquipPrice(uint256 tokenId, uint256 price) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipPrice, price.Uint256ToBytes());
return result;
}
function setEquipOfHorseId(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipOfHorseId, horseId.Uint256ToBytes());
return result;
}
function setEquipDis(uint256 tokenId, uint256 discount) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipDiscount, discount.Uint256ToBytes());
return result;
}
function setEquipReward(uint256 tokenId, uint256 reward) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipReward, reward.Uint256ToBytes());
return result;
}
function setEquipCoin(uint256 tokenId, uint256 coin) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipCoin, coin.Uint256ToBytes());
return result;
}
function setLastOperaTime1(uint256 tokenId, uint256 operaTime) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _lastOperaTime, operaTime.Uint256ToBytes());
return result;
}
function setLastOperaTime2(uint256 tokenId) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _lastOperaTime, block.timestamp.Uint256ToBytes());
return result;
}
function setEquipLastOwner(uint256 tokenId, address addr) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipLastOwner, addr.AddressToBytes());
return result;
}
function setEquipLastPrice(uint256 tokenId, uint256 price) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipLastPrice, price.Uint256ToBytes());
return result;
}
function getLastOperaTime(uint256 tokenId) public view returns (uint256){
bytes memory timeBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _lastOperaTime);
return timeBytes.BytesToUint256();
}
function getHorseEquipLastOwner(uint256 tokenId) public view returns (address){
bytes memory ownerBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipLastOwner);
return ownerBytes.BytesToAddress();
}
function getHorseEquipStatus(uint256 tokenId) public view returns (uint256){
bytes memory statusBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipStatus);
return statusBytes.BytesToUint256();
}
function getHorseEquipCoin(uint256 tokenId) public view returns (uint256){
bytes memory coinBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipCoin);
return coinBytes.BytesToUint256();
}
function getHorseEquipPrice(uint256 tokenId) public view returns (uint256){
bytes memory priceBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipPrice);
return priceBytes.BytesToUint256();
}
function getHorseEquipDiscount(uint256 tokenId) public view returns (uint256){
bytes memory DisBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipDiscount);
return DisBytes.BytesToUint256();
}
function getHorseEquipReward(uint256 tokenId) public view returns (uint256){
bytes memory rewBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipReward);
return rewBytes.BytesToUint256();
}
function getHorseEquipTypes(uint256 tokenId) public view returns (uint256){
bytes memory typesBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipTypes);
return typesBytes.BytesToUint256();
}
function getHorseEquipStyle(uint256 tokenId) public view returns (uint256){
bytes memory styleBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipStyle);
return styleBytes.BytesToUint256();
}
function getHorseEquipLastPrice(uint256 tokenId) public view returns (uint256){
bytes memory priceBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipLastPrice);
return priceBytes.BytesToUint256();
}
function getEquipOfHorseId(uint256 tokenId) public view returns (uint256){
bytes memory idBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipOfHorseId);
return idBytes.BytesToUint256();
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../library/Bytes.sol";
import "../game/Auth.sol";
import "../Interface/IERC721Token.sol";
import "../Interface/IERC721Attr.sol";
contract HorseRaceAttrOpera2_1V2 is Program {
using Bytes for bytes;
IERC721Attr private _horseRaceAttrAddress;
address private _horseRaceTokenAddress;
string public _headWearId ; //马头饰资产Id uint256
string public _armorId ; //马护甲资产Id uint256
string public _ponytailId ; //马尾饰资产Id uint256
string public _hoofId ; //马蹄饰资产Id uint256
string public _grade ; //马匹等级 uint256
string public _raceCount ; //参赛次数 uint256
string public _winCount ; //获赢次数 uint256
string public _raceId ; // 游戏服生成的竞赛唯一id
string public _raceType ;// 锦标赛/大奖赛/对决
string public _racecourse ;//报名比赛赛场资产唯一id
string public _distance ;//报名比赛赛程
string public _raceUpdateTime ;//报名/取消时间
string public _horseRaceStatus ;
string public _horseRaceDiscount ;
string public _horseRaceReward ;
string public _horseRaceCoin ;
string public _horseRaceLastOwner ; // 最后一次操作者
string public _horseRaceLastPrice ; // 最后一次成交价格
string public _horseRacePrice ; // 出售价格
string public _sellUpdateTime ; // 出售/取消出售时间
string public _studUpdateTime ; // 放入种马场/取消时间
function initialize() public initializer {
program_initialize();
_headWearId = "headWearId"; //马头饰资产Id uint256
_armorId = "armorId"; //马护甲资产Id uint256
_ponytailId = "ponytailId"; //马尾饰资产Id uint256
_hoofId = "hoofId"; //马蹄饰资产Id uint256
_grade = "grade"; //马匹等级 uint256
_raceCount = "raceCount"; //参赛次数 uint256
_winCount = "winCount"; //获赢次数 uint256
_raceId = "raceId"; // 游戏服生成的竞赛唯一id
_raceType = "raceType";// 锦标赛/大奖赛/对决
_racecourse = "racecourse";//报名比赛赛场资产唯一id
_distance = "distance";//报名比赛赛程
_raceUpdateTime = "raceUpdateTime";//报名/取消时间
_horseRaceStatus = "horseRaceStatus";
_horseRaceDiscount = "horseRaceDiscount";
_horseRaceReward = "horseRaceReward";
_horseRaceCoin = "horseRaceCoin";
_horseRaceLastOwner = "horseRaceLastOwner"; // 最后一次操作者
_horseRaceLastPrice = "horseRaceLastPrice"; // 最后一次成交价格
_horseRacePrice = "horseRacePrice"; // 出售价格
_sellUpdateTime = "sellUpdateTime"; // 出售/取消出售时间
_studUpdateTime = "studUpdateTime"; // 放入种马场/取消时间
}
function init(address raceAttrAddress, address horseRaceToken) public onlyAdmin returns (bool) {
_horseRaceAttrAddress = IERC721Attr(raceAttrAddress);
_horseRaceTokenAddress = horseRaceToken;
return true;
}
function getHeadWearId(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _headWearId);
return bytesInfo.BytesToUint256();
}
function getArmorId(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _armorId);
return bytesInfo.BytesToUint256();
}
function getPonytailId(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _ponytailId);
return bytesInfo.BytesToUint256();
}
function getHoofId(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _hoofId);
return bytesInfo.BytesToUint256();
}
function getGrade(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _grade);
return bytesInfo.BytesToUint256();
}
function getRaceCount(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _raceCount);
return bytesInfo.BytesToUint256();
}
function getWinCount(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _winCount);
return bytesInfo.BytesToUint256();
}
function getHorseRaceLastOwner(uint256 tokenId) public view returns (address){
bytes memory ownerBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _horseRaceLastOwner);
return ownerBytes.BytesToAddress();
}
function getHorseRaceStatus(uint256 tokenId) public view returns (uint256){
bytes memory statusBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _horseRaceStatus);
return statusBytes.BytesToUint256();
}
function getHorseRaceCoin(uint256 tokenId) public view returns (uint256){
bytes memory coinBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _horseRaceCoin);
return coinBytes.BytesToUint256();
}
function getHorseRacePrice(uint256 tokenId) public view returns (uint256){
bytes memory priceBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _horseRacePrice);
return priceBytes.BytesToUint256();
}
function getHorseRaceDiscount(uint256 tokenId) public view returns (uint256){
bytes memory DisBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _horseRaceDiscount);
return DisBytes.BytesToUint256();
}
function getHorseRaceReward(uint256 tokenId) public view returns (uint256){
bytes memory rewBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _horseRaceReward);
return rewBytes.BytesToUint256();
}
function getHorseRaceLastPrice(uint256 tokenId) public view returns (uint256){
bytes memory priceBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _horseRaceLastPrice);
return priceBytes.BytesToUint256();
}
function getSellUpdateTime(uint256 tokenId) public view returns (uint256){
bytes memory priceBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _sellUpdateTime);
return priceBytes.BytesToUint256();
}
function getStudUpdateTime(uint256 tokenId) public view returns (uint256){
bytes memory priceBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _studUpdateTime);
return priceBytes.BytesToUint256();
}
function getRaceId(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _raceId);
return bytesInfo.BytesToUint256();
}
function getRaceType(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _raceType);
return bytesInfo.BytesToUint256();
}
function getRacecourse(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _racecourse);
return bytesInfo.BytesToUint256();
}
function getDistance(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _distance);
return bytesInfo.BytesToUint256();
}
function getRaceUpdateTime(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenId, _raceUpdateTime);
return bytesInfo.BytesToUint256();
}
function checkStatus(uint256[] memory tokenIds, uint256 status) public view returns (bool){
require(tokenIds.length > 0 && tokenIds.length <= 256, "Cannot check 0 and must be less than 256");
for (uint256 i = 0; i < tokenIds.length; i++) {
bytes memory statusBytes = _horseRaceAttrAddress.getValue(address(_horseRaceTokenAddress), tokenIds[i], _horseRaceStatus);
if (statusBytes.BytesToUint256() != status) {
return false;
}
}
return true;
}
function checkGameInfo(uint256[] memory tokenIds, uint256 types, uint256 racecourseId,
uint256 level, uint256 distance) public view returns (bool){
require(tokenIds.length > 0 && tokenIds.length <= 256, "Cannot check 0 and must be less than 256");
for (uint256 i = 0; i < tokenIds.length; i++) {
if (getRaceType(tokenIds[i]) != types || getRacecourse(tokenIds[i]) != racecourseId
|| getDistance(tokenIds[i]) != distance || getGrade(tokenIds[i]) != level) {
return false;
}
}
return true;
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../Interface/IERC721Attr.sol";
import "../Interface/IERC721Token.sol";
import "../library/Bytes.sol";
import "../library/Uint256.sol";
import "../game/Auth.sol";
contract RacecourseAttrOperaContractV2 is Program {
using Uint256 for uint256;
using Bytes for bytes;
IERC721Attr private _attrAddress;
string public _horseId;//报名的马匹id
function initialize() public initializer {
program_initialize();
_horseId = "horseId";//报名的马匹id
}
function init(address attrAddress) public onlyAdmin returns (bool) {
_attrAddress = IERC721Attr(attrAddress);
return true;
}
function setHorseId(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _attrAddress.setArrayValue(tokenId, _horseId, horseId.Uint256ToBytes());
return result;
}
// 取消比赛后,清除已经报名的马匹信息
function delHorseId(uint256 tokenId) public onlyProgram returns (bool) {
bool result = _attrAddress.delArrayValue(tokenId, _horseId);
return result;
}
// 取消报名后,清除对应的马匹信息
function delHorseIdOne(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _attrAddress.removeArrayValue(tokenId, _horseId, horseId.Uint256ToBytes());
return result;
}
function delHorseIdBatch(uint256[] memory tokenIds) public onlyProgram returns (bool) {
require(tokenIds.length > 0 && tokenIds.length <= 256, "Cannot del 0 and must be less than 256");
for (uint256 i = 0; i < tokenIds.length; i++) {
_attrAddress.delArrayValue(tokenIds[i], _horseId);
}
return true;
}
function getHorseId(uint256 tokenId) public view returns (uint256[] memory) {
return _attrAddress.getArrayValue(tokenId, _horseId);
}
function checkHorseId(uint256 tokenId, uint256 horseId) external view returns (bool){
bool result = _attrAddress.checkArrayValue(tokenId, _horseId, horseId.Uint256ToBytes());
return result;
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../game/Auth.sol";
contract UserLoginContractV2 is Admin {
mapping(address => mapping(string => bool)) private _token;
mapping(address => mapping(string => uint256)) private _tokenExpTime;
function initialize() public initializer {
admin_initialize();
}
function reg(string memory token, uint256 time) public {
_token[msg.sender][token] = true;
_tokenExpTime[msg.sender][token] = block.timestamp + (time);
}
function logout(string memory token) public {
_token[msg.sender][token] = false;
_tokenExpTime[msg.sender][token] = block.timestamp;
}
function checkToken(address account, string memory token) public view returns (bool){
if (_token[account][token] && _tokenExpTime[account][token] > block.timestamp) {
return true;
}
return false;
}
function getUpgradeInfo() public pure returns (string memory) {
return "V2.0.0";
}
}
......@@ -63,7 +63,9 @@ module.exports = {
},
cmp_test: {
accounts: [privateKey],
url: "https://rpc.block.caduceus.global",
// url: "https://rpc.block.caduceus.global",
// url: "https://rpc.echain.bitheart.org",
url: "https://flashy-necessary-feather.bsc-testnet.quiknode.pro/",
},
mantle: {
accounts: [privateKey],
......
// scripts/deploy.js
async function main() {
const Box = await ethers.getContractFactory("Box");
console.log("Deploying Box...");
const box = await upgrades.deployProxy(Box, [42], { initializer: 'store' });
await box.waitForDeployment();
const boxAddress = await box.getAddress();
console.log("Box deployed to:", boxAddress);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
......@@ -469,13 +469,8 @@ async function deployMysteryBox(rewardToken, horseNFT, priceToken) {
}
function getContractAddr(contract) {
console.log("contract addr is ", contract.address);
// console.log("contract addr is ", contract.address);
return contract.address;
// var addr ;
// contract.getAddress().then((address) => {
// addr = address;
// });
// return addr
}
async function initialDeploy() {
......
/* eslint-disable prefer-const */
/* eslint-disable dot-notation */
/* eslint-disable no-unused-vars */
/* eslint-disable eqeqeq */
/* eslint-disable camelcase */
/* eslint-disable no-lone-blocks */
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
const upgradeAbleContracts = [
{addr: "0x452B05527F70bE30e16D01610C57E40c8ced54C6", name:"UserLogin", path:"UserLoginContract"},
{addr: "0xD5e6035CE7371d0C0664A4d152788D8411F71fe7", name:"Constant", path:"Constant"},
{addr: "0xa849f84Bf38175D618d3495310672E5DFfFd6D24", name:"Coin", path:"Coin"},
{addr: "0x92dC3A31960E920f00B526bEc4594CCF13D244BF", name:"Coin721", path:"Coin721"},
// {addr: "0xefB856A4A8fA069F60a41a2237a1eA4482FE7d4d", name:"NFTMysteryBoxOffering", path:"NFTMysteryBoxOffering"},
// {addr: "0xfd441677247Dd2961Bba8F46b4bb3D6598E172A3", name:"Random", path:"Random"},
// {addr: "0xE32902791FCC89047465392600af7CF08073DdA5", name:"Whitelist", path:"Whitelist"},
// {addr: "0xD9e4fAa4C31694FcdFcfa2eDE8C3Ae7D25F28AB6", name:"MysteryBox", path:"MysteryBox"},
// {addr: "0xb6b8A39137958B8DCd3A34E24A2E44787bc22bAF", name:"MysteryData", path:"MysteryData"},
// {addr: "0x196e5719F7983F8749A23B5142f7308f4196f6C3", name:"RaceBonusDistribute", path:"RaceBonusDistribute"},
// {addr: "0x6e0bBb19021E290eCA0366D14c9FcC66DB1E15f2", name:"RaceBonusPool", path:"RaceBonusPool"},
// {addr: "0x4f99c25aCA0d56Cf2E8E36D7e83C9a4329c5FB01", name:"RaceBonusData", path:"RaceBonusData"},
{addr: "0xeE60AB31Da5f991D89D8918e2c1a784EEDe41f7f", name:"RaceNFTAttr", path:"ERC721Attr"},
{addr: "0x897aF09d81d347BC4940E58157B672EdBC7Fa3Dd", name:"EquipAttr", path:"HorseEquipAttrOperaContract"},
{addr: "0xe40B9C2CAC590a45e666545862aA59a050f5C498", name:"ArenaAttr", path:"HorseArenaAttrOperaContract"},
{addr: "0x2bA3BD1bE12a696A5da58EF434d0Fa47B2bE4F5D", name:"RaceAttr1", path:"HorseRaceAttrOpera1"},
{addr: "0x7Fe9395130Db10cB7B1c547632602F6d5608d72b", name:"RaceAttr1_1", path:"HorseRaceAttrOpera1_1"},
{addr: "0x2d15B840CE5De85931d915003af44B29a78ae16D", name:"RaceAttr2", path:"HorseRaceAttrOpera2"},
{addr: "0xC7B7b222cB8E12EF1B73123732b3aFA94FE5b835", name:"RaceAttr2_1", path:"HorseRaceAttrOpera2_1"},
{addr: "0x147612b0E32B7Be28C32375A85B98A6b0FaF8d34", name:"HorseCourseAttr", path:"ERC721Attr"},
{addr: "0xC8574F717bc5C5A9B029eAd3Da669E745E101542", name:"HorseCourseAttrOpera", path:"RacecourseAttrOperaContract"},
{addr: "0x3BCC634C43c15971623d5E33475b1732553440b9", name:"EquipExtra", path:"HorseEquipContract"},
{addr: "0x6bE51BD56aabAC86A8b0E62F7e23f2Aa49Bc92ac", name:"RaceExtra", path:"HorseRaceContract"},
{addr: "0x1C961B7373a5cF966F45Ab9Ad493C405943b3e3a", name:"RaceExtra1", path:"HorseRaceExtra1"},
{addr: "0xdb6e69467083fbe6AAE0dff0823353Ce82c8c35f", name:"RaceExtra2", path:"HorseRaceExtra2"},
{addr: "0x83c812Cd6e4ea911a9628bcDEBc48c079C92dC68", name:"ArenaExtra", path:"HorseArenaContract"},
{addr: "0xd1933659411d0Fe803f6eC24F6b47627210C5Db0", name:"ArenaExtra1", path:"HorseArenaExtra"},
{addr: "0x5A952fbb82E3c1238d9692126A77002675A1D80f", name:"ArenaExtra2", path:"HorseArenaExtra2"},
{addr: "0x82a947F3D70C86E8Fc01d70414650fA29d9578d4", name:"ArenaExtra3", path:"HorseArenaExtra3"}
]
let ContractMap = new Map();
async function getContract(contractPath, address) {
return await hre.ethers.getContractAt(contractPath, address);
}
async function upgradeContract(proxyAddress, contractName, contractPath) {
const newContract = await ethers.getContractFactory(contractPath);
console.log("upgrade " + contractPath + " to " + proxyAddress);
const nContract = await upgrades.upgradeProxy(proxyAddress, newContract);
await nContract.waitForDeployment();
const nAddress = await nContract.getAddress();
console.log(contractName + " deploy at:", nAddress);
}
async function upgradeAllContracts() {
for (let i = 0; i < upgradeAbleContracts.length; i++) {
const contract = upgradeAbleContracts[i];
const addr = contract.addr;
const name = contract.name;
const path = contract.path;
var newPath = path + "V2";
await upgradeContract(addr, name, newPath);
}
for (let i = 0; i < upgradeAbleContracts.length; i++) {
const contract = upgradeAbleContracts[i];
const addr = contract.addr;
const name = contract.name;
const path = contract.path;
var newPath = path + "V2";
const contractObj = await getContract(newPath, addr);
const version = await contractObj.getUpgradeInfo();
console.log("contract ", name, " version is ", version);
}
}
async function main() {
await upgradeAllContracts();
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
// scripts/prepare_upgrade.js
async function main() {
const proxyAddress = '0x863dCa3ec27b12D2005f3cD857eD56153852B224';
const BoxV2 = await ethers.getContractFactory("BoxV2");
console.log("upgrade...");
const boxv2 = await upgrades.upgradeProxy(proxyAddress, BoxV2);
await boxv2.waitForDeployment();
const boxv2Address = await boxv2.getAddress();
console.log("BoxV2 at:", boxv2Address);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
// test/Box.js
// Load dependencies
const { expect } = require('chai');
let Box;
let box;
// Start test block
describe('Box', function () {
beforeEach(async function () {
Box = await ethers.getContractFactory("Box");
box = await Box.deploy();
});
// Test case
it('retrieve returns a value previously stored', async function () {
// Store a value
await box.store(42);
// Test if the returned value is the same one
// Note that we need to use strings to compare the 256 bit integers
expect((await box.retrieve()).toString()).to.equal('42');
});
});
// test/Box.proxy.js
// Load dependencies
const { expect } = require('chai');
let Box;
let box;
// Start test block
describe('Box (proxy)', function () {
beforeEach(async function () {
Box = await ethers.getContractFactory("Box");
box = await upgrades.deployProxy(Box, [42], {initializer: 'store'});
});
// Test case
it('retrieve returns a value previously initialized', async function () {
// Test if the returned value is the same one
// Note that we need to use strings to compare the 256 bit integers
expect((await box.retrieve()).toString()).to.equal('42');
});
});
// test/BoxV2.js
// Load dependencies
const { expect } = require('chai');
let BoxV2;
let boxV2;
// Start test block
describe('BoxV2', function () {
beforeEach(async function () {
BoxV2 = await ethers.getContractFactory("BoxV2");
boxV2 = await BoxV2.deploy();
});
// Test case
it('retrieve returns a value previously stored', async function () {
// Store a value
await boxV2.store(42);
// Test if the returned value is the same one
// Note that we need to use strings to compare the 256 bit integers
expect((await boxV2.retrieve()).toString()).to.equal('42');
});
// Test case
it('retrieve returns a value previously incremented', async function () {
// Increment
await boxV2.increment();
// Test if the returned value is the same one
// Note that we need to use strings to compare the 256 bit integers
expect((await boxV2.retrieve()).toString()).to.equal('1');
});
});
This diff is collapsed.
This diff is collapsed.
#!/bin/bash
network=${1:-"httest"}
if [ ! -e "./.secret" ]
then
echo "You must set DEPLOY_PRIVATE_KEY and NAME_SIGNER_KEY in .secret file"
exit
fi
if [ -e ".env" ]
then
cp .env .env_bak
rm -rf .env
fi
cat .secret >> .env
echo "" >> .env
cat "./config/$network.cfg" >> .env
npx hardhat run scripts/testUpgrade.js --network $network
rm -rf .env
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment