Skip to content

Commit

Permalink
Merge pull request #633 from rndquu/test/rmv-difficulty
Browse files Browse the repository at this point in the history
test: remove difficulty from UbiquiStick tests
  • Loading branch information
0x4007 authored May 28, 2023
2 parents 160fd6d + 0a8326a commit 8072e38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"ntype",
"opentype",
"Pausable",
"prevrandao",
"proto",
"psender",
"Qmanager",
Expand Down
42 changes: 17 additions & 25 deletions packages/contracts/test/ubiquistick/UbiquiStick.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,19 @@ contract UbiquiStickTest is Test {

function testTokenURI_ShouldReturnTokenURIForTokenTypeGold() public {
// set gold token URI
vm.prank(minter);
vm.startPrank(minter);
ubiquiStick.setTokenURI(GOLD_TYPE, "TOKEN_URI_GOLD");
// mint gold token
// mint 80 tokens to user (needed for random() to return a gold type)
for (uint256 i = 1; i <= 80; i++) {
vm.prank(minter);
// mint 57 tokens to user (needed for random() to return a gold type)
for (uint i = 1; i <= 57; i++) {
ubiquiStick.safeMint(user);
}
// mock EVM values so that random() could return a gold token
vm.warp(1);
vm.difficulty(81);
// mint 81st gold token
vm.prank(minter);
// with the default "block.prevrandao = 0" the 58th token is gold
ubiquiStick.safeMint(user);

assertEq(ubiquiStick.tokenURI(81), "TOKEN_URI_GOLD");
assertEq(ubiquiStick.tokenURI(58), "TOKEN_URI_GOLD");

vm.stopPrank();
}

function testTokenURI_ShouldReturnTokenURIForTokenTypeInvisible() public {
Expand Down Expand Up @@ -140,21 +137,17 @@ contract UbiquiStickTest is Test {
}

function testSafeMint_ShouldMintGoldToken() public {
// mint 80 tokens to user (needed for random() to return a gold type)
for (uint256 i = 1; i <= 80; i++) {
vm.prank(minter);
vm.startPrank(minter);
// mint 57 tokens to user (needed for random() to return a gold type)
for (uint i = 1; i <= 57; i++) {
ubiquiStick.safeMint(user);
}

// mock EVM values so that random() could return a gold token
vm.warp(1);
vm.difficulty(81);

// mint 81st token
vm.prank(minter);
// with the default "block.prevrandao = 0" the 58th token is gold
ubiquiStick.safeMint(user);
assertEq(ubiquiStick.ownerOf(81), user);
assertEq(ubiquiStick.gold(81), true);
assertEq(ubiquiStick.ownerOf(58), user);
assertEq(ubiquiStick.gold(58), true);

vm.stopPrank();
}

function testBatchSafeMint_ShouldRevert_IfCalledNotByMinter() public {
Expand All @@ -171,11 +164,10 @@ contract UbiquiStickTest is Test {
}

function testRandom_ShouldReturnRandomValue() public {
vm.warp(1);
vm.difficulty(1);
// by default "block.prevrandao = 0"
assertEq(
ubiquiStick.exposed_random(),
12751150048135892262188697730632532742577045435178855596188279334644121003250
59314673252666873280629439252894990696031209845167399747113266702537979136323
);
}

Expand Down

0 comments on commit 8072e38

Please sign in to comment.