-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrey Korokhov
committed
May 16, 2024
1 parent
26a1a7a
commit b69a64d
Showing
10 changed files
with
506 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {Test, console2} from "forge-std/Test.sol"; | ||
|
||
import {NonMigratablesRegistry} from "src/contracts/NonMigratablesRegistry.sol"; | ||
import {INonMigratablesRegistry} from "src/interfaces/INonMigratablesRegistry.sol"; | ||
|
||
contract NonMigratablesRegistryTest is Test { | ||
address owner; | ||
address alice; | ||
uint256 alicePrivateKey; | ||
address bob; | ||
uint256 bobPrivateKey; | ||
|
||
INonMigratablesRegistry registry; | ||
|
||
function setUp() public { | ||
owner = address(this); | ||
(alice, alicePrivateKey) = makeAddrAndKey("alice"); | ||
(bob, bobPrivateKey) = makeAddrAndKey("bob"); | ||
} | ||
|
||
function test_Create() public { | ||
registry = new NonMigratablesRegistry(); | ||
|
||
assertEq(registry.isEntity(alice), false); | ||
} | ||
|
||
function test_Register() public { | ||
registry = new NonMigratablesRegistry(); | ||
|
||
vm.startPrank(alice); | ||
registry.register(); | ||
vm.stopPrank(); | ||
|
||
assertEq(registry.isEntity(alice), true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {Test, console2} from "forge-std/Test.sol"; | ||
|
||
import {NonMigratablesRegistry} from "src/contracts/NonMigratablesRegistry.sol"; | ||
import {IPlugin} from "src/interfaces/IPlugin.sol"; | ||
|
||
import {SimplePlugin} from "./mocks/SimplePlugin.sol"; | ||
|
||
contract PluginTest is Test { | ||
address owner; | ||
address alice; | ||
uint256 alicePrivateKey; | ||
address bob; | ||
uint256 bobPrivateKey; | ||
|
||
NonMigratablesRegistry registry; | ||
|
||
SimplePlugin plugin; | ||
|
||
function setUp() public { | ||
owner = address(this); | ||
(alice, alicePrivateKey) = makeAddrAndKey("alice"); | ||
(bob, bobPrivateKey) = makeAddrAndKey("bob"); | ||
|
||
registry = new NonMigratablesRegistry(); | ||
} | ||
|
||
function test_Create(uint256 number) public { | ||
plugin = new SimplePlugin(address(registry)); | ||
|
||
assertEq(plugin.REGISTRY(), address(registry)); | ||
assertEq(plugin.number(alice), 0); | ||
|
||
vm.startPrank(alice); | ||
registry.register(); | ||
vm.stopPrank(); | ||
|
||
vm.startPrank(alice); | ||
plugin.setNumber(number); | ||
vm.stopPrank(); | ||
|
||
assertEq(plugin.number(alice), number); | ||
} | ||
|
||
function test_SetNumberRevertNotEntity(uint256 number) public { | ||
plugin = new SimplePlugin(address(registry)); | ||
|
||
vm.startPrank(alice); | ||
vm.expectRevert(IPlugin.NotEntity.selector); | ||
plugin.setNumber(number); | ||
vm.stopPrank(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {Plugin} from "src/contracts/Plugin.sol"; | ||
|
||
contract SimplePlugin is Plugin { | ||
mapping(address entity => uint256 value) public number; | ||
|
||
constructor(address registry) Plugin(registry) {} | ||
|
||
function setNumber(uint256 number_) external onlyEntity { | ||
number[msg.sender] = number_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {Test, console2} from "forge-std/Test.sol"; | ||
|
||
import {NonMigratablesRegistry} from "src/contracts/NonMigratablesRegistry.sol"; | ||
import {IPlugin} from "src/interfaces/IPlugin.sol"; | ||
|
||
import {MetadataPlugin} from "src/contracts/plugins/MetadataPlugin.sol"; | ||
import {IMetadataPlugin} from "src/interfaces/plugins/IMetadataPlugin.sol"; | ||
|
||
contract MetadataPluginTest is Test { | ||
address owner; | ||
address alice; | ||
uint256 alicePrivateKey; | ||
address bob; | ||
uint256 bobPrivateKey; | ||
|
||
NonMigratablesRegistry registry; | ||
|
||
IMetadataPlugin plugin; | ||
|
||
function setUp() public { | ||
owner = address(this); | ||
(alice, alicePrivateKey) = makeAddrAndKey("alice"); | ||
(bob, bobPrivateKey) = makeAddrAndKey("bob"); | ||
|
||
registry = new NonMigratablesRegistry(); | ||
} | ||
|
||
function test_Create(string calldata metadataURL_) public { | ||
plugin = IMetadataPlugin(address(new MetadataPlugin(address(registry)))); | ||
|
||
assertEq(plugin.metadataURL(alice), ""); | ||
|
||
vm.startPrank(alice); | ||
registry.register(); | ||
vm.stopPrank(); | ||
|
||
vm.startPrank(alice); | ||
plugin.setMetadataURL(metadataURL_); | ||
vm.stopPrank(); | ||
|
||
assertEq(plugin.metadataURL(alice), metadataURL_); | ||
} | ||
|
||
function test_SetNumberRevertNotEntity(string calldata metadataURL_) public { | ||
plugin = IMetadataPlugin(address(new MetadataPlugin(address(registry)))); | ||
|
||
vm.startPrank(alice); | ||
vm.expectRevert(IPlugin.NotEntity.selector); | ||
plugin.setMetadataURL(metadataURL_); | ||
vm.stopPrank(); | ||
} | ||
} |
Oops, something went wrong.