Skip to content

Commit 11b827c

Browse files
authored
Merge pull request #3 from TSxo/proxy
feat: CallContext
2 parents d8acc7a + e60da73 commit 11b827c

13 files changed

Lines changed: 166 additions & 45 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ The smart contracts are located in the `src` directory.
1818
│   ├── IAuthManager.sol
1919
│   └── IAuthority.sol
2020
├── mixins
21+
│   ├── CallContext.sol
2122
│   └── Mutex.sol
23+
└── proxy
24+
├── Proxy.sol
2225
```
2326

2427
## Purpose & License
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity 0.8.20;
44

55
import { Owned } from "@tsxo/libsol/auth/Owned.sol";
66

7-
contract OwnedImpl is Owned {
7+
contract OwnedMock is Owned {
88
uint256 public count;
99

1010
constructor(address initialOwner) {

src/mocks/auth/managed/AuthManagedImpl.sol renamed to src/mocks/auth/managed/AuthManagedMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity 0.8.20;
44

55
import { AuthManaged } from "@tsxo/libsol/auth/managed/AuthManaged.sol";
66

7-
contract AuthManagedImpl is AuthManaged {
7+
contract AuthManagedMock is AuthManaged {
88
uint256 public count;
99

1010
constructor(address initialAuthority) {

src/mocks/auth/managed/AuthManagerImpl.sol renamed to src/mocks/auth/managed/AuthManagerMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity 0.8.20;
55
import { AuthManager } from "@tsxo/libsol/auth/managed/AuthManager.sol";
66
import { Owned } from "@tsxo/libsol/auth/Owned.sol";
77

8-
contract AuthManagerImpl is Owned, AuthManager {
8+
contract AuthManagerMock is Owned, AuthManager {
99
constructor(address initialOwner) {
1010
_initializeOwned(initialOwner);
1111
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.20;
4+
5+
import { CallContext } from "@tsxo/libsol/mixins/CallContext.sol";
6+
import { Proxy } from "@tsxo/libsol/proxy/Proxy.sol";
7+
8+
contract CallContextMock is CallContext {
9+
function implementationCall() public view returns (bool) {
10+
return _implementationCall();
11+
}
12+
13+
function selfAddress() public view returns (address) {
14+
return _self();
15+
}
16+
17+
function assertImplCall() public view notDelegated { }
18+
19+
function assertProxyCall() public view onlyProxy { }
20+
}
21+
22+
contract CallContextProxy is Proxy {
23+
address immutable _target;
24+
25+
constructor(address target) {
26+
_target = target;
27+
}
28+
29+
function _implementation() internal view override returns (address result) {
30+
return _target;
31+
}
32+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
44

55
import { Mutex } from "@tsxo/libsol/mixins/Mutex.sol";
66

7-
contract MutexImpl is Mutex {
7+
contract MutexMock is Mutex {
88
uint256 private _count;
99

1010
constructor() {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
44

55
import { Proxy } from "@tsxo/libsol/proxy/Proxy.sol";
66

7-
contract ProxyImpl is Proxy {
7+
contract ProxyMock is Proxy {
88
address immutable _target;
99

1010
constructor(address target) {

test/auth/Owned.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pragma solidity 0.8.20;
22

33
import { Test } from "forge-std/Test.sol";
44
import { IOwned } from "@tsxo/libsol/auth/IOwned.sol";
5-
import { OwnedImpl } from "@tsxo/libsol/mocks/auth/OwnedImpl.sol";
5+
import { OwnedMock } from "@tsxo/libsol/mocks/auth/OwnedMock.sol";
66

77
interface TestEvents {
88
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
@@ -12,14 +12,14 @@ contract OwnedTest is Test, TestEvents {
1212
// -------------------------------------------------------------------------
1313
// State
1414

15-
OwnedImpl owned;
15+
OwnedMock owned;
1616
address constant owner = address(0x1234);
1717

1818
// -------------------------------------------------------------------------
1919
// Set Up
2020

2121
function setUp() public {
22-
owned = new OwnedImpl(owner);
22+
owned = new OwnedMock(owner);
2323
}
2424

2525
// -------------------------------------------------------------------------
@@ -32,7 +32,7 @@ contract OwnedTest is Test, TestEvents {
3232
function test_RevertsOnConstructionWithZeroAddress() public {
3333
bytes4 err = IOwned.Owned__ZeroAddress.selector;
3434
vm.expectRevert(err);
35-
new OwnedImpl(address(0));
35+
new OwnedMock(address(0));
3636
}
3737

3838
// -------------------------------------------------------------------------

test/auth/managed/AuthManaged.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { Test } from "forge-std/Test.sol";
55
import { IAuthManaged } from "@tsxo/libsol/auth/managed/IAuthManaged.sol";
66
import { IAuthManager } from "@tsxo/libsol/auth/managed/IAuthManager.sol";
77

8-
import { AuthManagedImpl } from "@tsxo/libsol/mocks/auth/managed/AuthManagedImpl.sol";
9-
import { AuthManagerImpl } from "@tsxo/libsol/mocks/auth/managed/AuthManagerImpl.sol";
8+
import { AuthManagedMock } from "@tsxo/libsol/mocks/auth/managed/AuthManagedMock.sol";
9+
import { AuthManagerMock } from "@tsxo/libsol/mocks/auth/managed/AuthManagerMock.sol";
1010

1111
interface TestEvents {
1212
event AuthorityUpdated(address indexed previousAuthority, address indexed newAuthority);
@@ -23,15 +23,15 @@ contract AuthManagedTest is Test, TestEvents {
2323
address constant owner = address(0x1234);
2424
address constant user = address(0x2345);
2525

26-
AuthManagerImpl manager;
27-
AuthManagedImpl managed;
26+
AuthManagerMock manager;
27+
AuthManagedMock managed;
2828

2929
// -------------------------------------------------------------------------
3030
// Set Up
3131

3232
function setUp() public {
33-
manager = new AuthManagerImpl(owner);
34-
managed = new AuthManagedImpl(address(manager));
33+
manager = new AuthManagerMock(owner);
34+
managed = new AuthManagedMock(address(manager));
3535
}
3636

3737
// -------------------------------------------------------------------------

test/auth/managed/AuthManager.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { Test } from "forge-std/Test.sol";
55
import { IAuthManaged } from "@tsxo/libsol/auth/managed/IAuthManaged.sol";
66
import { IAuthManager } from "@tsxo/libsol/auth/managed/IAuthManager.sol";
77

8-
import { AuthManagedImpl } from "@tsxo/libsol/mocks/auth/managed/AuthManagedImpl.sol";
9-
import { AuthManagerImpl } from "@tsxo/libsol/mocks/auth/managed/AuthManagerImpl.sol";
8+
import { AuthManagedMock } from "@tsxo/libsol/mocks/auth/managed/AuthManagedMock.sol";
9+
import { AuthManagerMock } from "@tsxo/libsol/mocks/auth/managed/AuthManagerMock.sol";
1010

1111
interface TestEvents {
1212
event UserRoleUpdated(address indexed user, uint8 indexed role, bool enabled);
@@ -28,15 +28,15 @@ contract AuthManagerTest is Test, TestEvents {
2828
address constant userB = address(0x3456);
2929
address constant userC = address(0x4567);
3030

31-
AuthManagerImpl manager;
32-
AuthManagedImpl managed;
31+
AuthManagerMock manager;
32+
AuthManagedMock managed;
3333

3434
// -------------------------------------------------------------------------
3535
// Set Up
3636

3737
function setUp() public {
38-
manager = new AuthManagerImpl(owner);
39-
managed = new AuthManagedImpl(address(manager));
38+
manager = new AuthManagerMock(owner);
39+
managed = new AuthManagedMock(address(manager));
4040
}
4141

4242
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)