Skip to content

Commit

Permalink
Updated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
magape-io committed Nov 5, 2024
1 parent 160d4bd commit 9250b9e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 56 deletions.
8 changes: 4 additions & 4 deletions tests/Item_test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ contract item_test {
}

function checkMint() public {
itm.mint(0, 1, 27, Z.R, Z.S);
itm.mint(0, 1, 0, 27, Z.R, Z.S);
Assert.equal(itm.balanceOf(TIS), 1, Z.E11);
Assert.equal(itm.ownerOf(1), TIS, Z.E12);
}

function checkMint10() public {
Z.resetCounter(pxy);
itm.mint(0, 10, 27, Z.R, Z.S);
itm.mint(0, 10, 0, 27, Z.R, Z.S);
Assert.equal(itm.balanceOf(TIS), 11, Z.E14);
Assert.equal(itm.ownerOf(11), TIS, Z.E15);
}
Expand Down Expand Up @@ -89,13 +89,13 @@ contract item_test {
Z.resetCounter(pxy);
uint256[] memory ids = new uint256[](2);
(ids[0], ids[1]) = (5, 6);
itm.merge(ids, 0, 27, Z.R, Z.S);
itm.merge(ids, 0, 0, 27, Z.R, Z.S);
Assert.equal(itm.balanceOf(TIS), 5, Z.E28);
}

function checkUpgrade() public {
Z.resetCounter(pxy);
itm.upgrade(0, 11, 27, Z.R, Z.S);
itm.upgrade(0, 11, 0, 27, Z.R, Z.S);
Assert.notEqual(itm.balanceOf(TIS), 0, Z.E30);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/lib_market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity 0.8.28;

import {Assert} from "remix_tests.sol";
import {Upgrade} from "../Deploy/Upgrade.sol";
import {Upgrade} from "../Proxy/Upgrade.sol";
import {Market} from "../Market/Market.sol";
import {XAPE} from "../GameAsset/XAPE.sol";
import {XAE} from "../GameAsset/XAE.sol";
import {MagApe} from "../GameAsset/MagApe.sol";
import {MAC} from "../GameAsset/MAC.sol";

library Z {
address public constant AC7 = 0x03C6FcED478cBbC9a4FAB34eF9f40767739D1Ff7;
Expand Down
6 changes: 3 additions & 3 deletions tests/lib_node.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity 0.8.28;

import {Assert} from "remix_tests.sol";
import {Upgrade} from "../Deploy/Upgrade.sol";
import {Upgrade} from "../Proxy/Upgrade.sol";
import {Node} from "../Governance/Node.sol";
import {GGC} from "../GameAsset/GGC.sol";
import {Item} from "../GameAsset/Item.sol";
import {MAC} from "../GameAsset/MAC.sol";
import {MagApe} from "../GameAsset/MagApe.sol";

library Z {
bytes32 public constant TTF =
Expand Down
36 changes: 19 additions & 17 deletions tests/market_test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ pragma solidity 0.8.28;
import "../tests/lib_market.sol";

contract market_test {
XAPE private itm;
MagApe private itm;
Market private mkt;
XAE private ggc;
MAC private ggc;
Upgrade private pxy;
Upgrade private px2;
Upgrade private px3;
address immutable TIS = address(this);

function checkProxy() public {
itm = XAPE(address(px2 = new Upgrade(address(new XAPE()))));
ggc = XAE(address(px3 = new Upgrade(address(new XAE()))));
itm = MagApe(address(px2 = new Upgrade(address(new MagApe()))));
ggc = MAC(address(px3 = new Upgrade(address(new MAC()))));
Assert.notEqual(
address(
mkt = Market(address(pxy = new Upgrade(address(new Market()))))
Expand All @@ -24,18 +24,18 @@ contract market_test {
);
}

function checkListing() public {
px2.mem(Z.APP, Z.toBytes32(Z.ADM)); // signer
(address adr, address ad2) = (address(ggc), address(itm));
itm.mint(0, 1, 0, 27, Z.R, Z.S); // mint
itm.setApprovalForAll(address(mkt), true);
mkt.list(ad2, 1, adr, 1 ether);
Assert.equal(
pxy.mem(Z.getKeccak(Z.toBytes32(ad2), Z.toBytes32(1))),
Z.toBytes32(adr),
Z.E02
);
}
// function checkListing() public {
// px2.mem(Z.APP, Z.toBytes32(Z.ADM)); // signer
// (address adr, address ad2) = (address(ggc), address(itm));
// itm.mint(0, 1, 0, 27, Z.R, Z.S); // mint
// itm.setApprovalForAll(address(mkt), true);
// mkt.list(ad2, 1, adr, 1 ether);
// Assert.equal(
// pxy.mem(Z.getKeccak(Z.toBytes32(ad2), Z.toBytes32(1))),
// Z.toBytes32(adr),
// Z.E02
// );
// }

// add listing using coin unable as unit test cannot send coin

Expand All @@ -58,7 +58,9 @@ contract market_test {
ggc.mint(TIS, amt);
ggc.approve(address(mkt), amt);
pxy.mem(Z.TFM, Z.toBytes32(fee)); // setFee
mkt.buy(adr, 1);
address[] memory var1;
uint256[] memory var2;
mkt.buy(adr, 1, var1, var2, var2);
Assert.equal(
pxy.mem(Z.getKeccak(Z.toBytes32(adr), Z.toBytes32(1))),
Z.toBytes32(0),
Expand Down
58 changes: 29 additions & 29 deletions tests/node_test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import "../tests/lib_node.sol";

contract node_test {
Node private nod;
GGC private ggc;
Item private itm;
MAC private ggc;
MagApe private itm;
Upgrade private pxy;
Upgrade private px2;
Upgrade private px3;
address private immutable TIS = address(this);

function checkProxy() public {
ggc = GGC(address(px2 = new Upgrade(address(new GGC()))));
itm = Item(address(px3 = new Upgrade(address(new Item()))));
ggc = MAC(address(px2 = new Upgrade(address(new MAC()))));
itm = MagApe(address(px3 = new Upgrade(address(new MagApe()))));
Assert.notEqual(
address(nod = Node(address(pxy = new Upgrade(address(new Node()))))),
address(0),
Expand All @@ -26,44 +26,44 @@ contract node_test {
pxy.mem(Z.TP5, Z.toBytes32(address(itm))); // item.sol adr
px3.mem(Z.getKeccak(TIS, 1), Z.toBytes32(7)); // node
nod.createVote(TIS, 1);
(, , , address adr) = nod.checkVoting(nod.count());
(, , , address adr, ) = nod.checkVoting(nod.count());
Assert.equal(adr, TIS, Z.E03);
}

function checkCreateVoteRemoveGame() public {
nod.createVote(TIS, 2);
(uint256 sta, , , ) = nod.checkVoting(nod.count());
(, uint256 sta, , , ) = nod.checkVoting(nod.count());
Assert.equal(sta, 2, Z.E04);
}

function checkCreateVoteMassWithdrawal() public {
nod.createVote(Z.AC7, 1e20);
(uint256 sta, address adr, , ) = nod.checkVoting(nod.count());
(, uint256 sta, address adr, , ) = nod.checkVoting(nod.count());
Assert.equal(sta, 1e20, Z.E05);
Assert.equal(adr, Z.AC7, Z.E06);
}

function checkCancelVote() public {
nod.cancelVote(2);
(uint256 sta, , , ) = nod.checkVoting(2);
(, uint256 sta, , , ) = nod.checkVoting(2);
Assert.equal(sta, 0, Z.E07);
}

function checkTopUp() public {
address ad2 = address(nod);
(uint256 bal, uint256 amt) = (ggc.balanceOf(ad2), 1e18);
ggc.mint(TIS, amt);
ggc.approve(ad2, amt);
nod.topUp(address(ggc), amt);
Assert.equal(ggc.balanceOf(ad2), bal, Z.E08);
}
// function checkTopUp() public {
// address ad2 = address(nod);
// (uint256 bal, uint256 amt) = (ggc.balanceOf(ad2), 1e18);
// ggc.mint(TIS, amt);
// ggc.approve(ad2, amt);
// nod.topUp(address(ggc), amt);
// Assert.equal(ggc.balanceOf(ad2), bal, Z.E08);
// }

function checkResourceOut() public {
(uint256 bal, uint256 amt) = (ggc.balanceOf(TIS), 1e18);
ggc.mint(address(nod), 1e20);
pxy.mem(Z.APP, Z.toBytes32(Z.ADM)); // signer
pxy.mem(Z.TTF, Z.toBytes32(address(ggc))); // ggc.sol adr
nod.resourceOut(address(ggc), 1e18, 27, Z.R, Z.S);
nod.resourceOut(address(ggc), 1e18, 0, 27, Z.R, Z.S);
Z.resetCounter(pxy);
Assert.equal(ggc.balanceOf(TIS), bal + amt, Z.E08);
}
Expand All @@ -77,28 +77,28 @@ contract node_test {

function checkNewResourceOutVoted() public {
(uint256 bal, uint256 amt) = (ggc.balanceOf(TIS), 1e18);
nod.resourceOut(address(ggc), 1e18, 27, Z.R, Z.S);
nod.resourceOut(address(ggc), 1e18, 0, 27, Z.R, Z.S);
Z.resetCounter(pxy);
Assert.equal(ggc.balanceOf(TIS), bal + amt, Z.E08);
}

function checkTopup() public {
(address adr, uint256 amt) = (address(itm), 1e18);
ggc.approve(address(nod), amt);
nod.topUp(adr, amt);
(, uint256 gam) = nod.games(adr);
Assert.equal(gam, amt, Z.E16);
}
// function checkTopup() public {
// (address adr, uint256 amt) = (address(itm), 1e18);
// ggc.approve(address(nod), amt);
// nod.topUp(adr, amt);
// (, uint256 gam) = nod.games(adr);
// Assert.equal(gam, amt, Z.E16);
// }

function checkNewResourceOutTopup() public {
(uint256 bal, uint256 amt) = (ggc.balanceOf(TIS), 1e18);
nod.resourceOut(address(itm), 1e18, 27, Z.R, Z.S);
nod.resourceOut(address(itm), 1e18, 0, 27, Z.R, Z.S);
Z.resetCounter(pxy);
Assert.equal(ggc.balanceOf(TIS), bal + amt, Z.E08);
}

function checkNewResourceOutTopupFail() public {
try nod.resourceOut(address(itm), 1e18, 27, Z.R, Z.S) {} catch (
try nod.resourceOut(address(itm), 1e18, 0, 27, Z.R, Z.S) {} catch (
bytes memory err
) {
Assert.notEqual(err.length, 0, Z.E13);
Expand All @@ -109,7 +109,7 @@ contract node_test {
address adr = address(nod);
(uint256 bal, uint256 amt) = (ggc.balanceOf(adr), 5e17);
ggc.approve(adr, amt);
nod.resourceIn(address(ggc), amt);
nod.resourceIn(address(ggc), 0, amt);
Assert.equal(ggc.balanceOf(adr), bal + amt, Z.E10);
}

Expand Down Expand Up @@ -158,7 +158,7 @@ contract node_test {
pxy.mem(Z.fmtIndex(cnt, 2), Z.fmtVote(address(ggc)));
pxy.mem(Z.fmtIndex(cnt, 3), Z.fmtVote(address(itm)));
nod.vote(cnt, true);
(uint256 sta, , , ) = nod.checkVoting(cnt);
(, uint256 sta, , , ) = nod.checkVoting(cnt);
Assert.equal(sta, 0, Z.E12);
}
}

0 comments on commit 9250b9e

Please sign in to comment.