Skip to content

Commit 730fc4f

Browse files
committed
Refactor contract
1 parent 8596d5c commit 730fc4f

File tree

6 files changed

+25
-136
lines changed

6 files changed

+25
-136
lines changed

accs-contract-call/contracts/src/AccessControl.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ pragma solidity ^0.8.13;
44
contract AccessControl {
55
mapping(address => bool) public revokedAccess;
66

7-
function grantAccess(address user) public {
8-
revokedAccess[user] = false;
7+
function grantAccess() public {
8+
revokedAccess[msg.sender] = false;
99
}
1010

11-
function revokeAccess(address user) public {
12-
revokedAccess[user] = true;
11+
function revokeAccess() public {
12+
revokedAccess[msg.sender] = true;
1313
}
1414

1515
function hasRevokedAccess(address user) public view returns (bool) {

accs-contract-call/contracts/test/AccessControl.t.sol

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,33 @@ contract AccessControlTest is Test {
1010
function setUp() public {
1111
accessControl = new AccessControl();
1212
}
13+
14+
function testGrantedByDefault() public {
15+
address user = address(this);
16+
assertFalse(accessControl.hasRevokedAccess(user));
17+
}
1318

1419
function testGrantAccess() public {
15-
address user = address(0xBEEF);
16-
accessControl.grantAccess(user);
20+
address user = address(this);
21+
accessControl.grantAccess();
1722
assertFalse(accessControl.hasRevokedAccess(user));
1823
}
1924

2025
function testRevokeAccess() public {
21-
address user = address(0xCAFE);
22-
accessControl.revokeAccess(user);
26+
address user = address(this);
27+
accessControl.revokeAccess();
2328
assertTrue(accessControl.hasRevokedAccess(user));
2429
}
2530

2631
function testHasRevokedAccess() public {
27-
address user1 = address(0xDEAD);
32+
address user1 = address(this);
2833
address user2 = address(0xFEED);
2934

30-
accessControl.revokeAccess(user1);
31-
accessControl.grantAccess(user2);
35+
vm.prank(user1);
36+
accessControl.revokeAccess();
37+
38+
vm.prank(user2);
39+
accessControl.grantAccess();
3240

3341
assertTrue(accessControl.hasRevokedAccess(user1));
3442
assertFalse(accessControl.hasRevokedAccess(user2));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
ETHEREUM_PRIVATE_KEY=
2-
DEPLOYED_ACCESS_CONTROL_CONTRACT_ADDRESS=0xf960775B87fF2f53Eb962A8845F647615047389E
2+
DEPLOYED_ACCESS_CONTROL_CONTRACT_ADDRESS=0x4fc0c02ebbAbb81C04dB0C462C8c25cb37970eB1
33
LIT_CAPACITY_CREDIT_TOKEN_ID=

accs-contract-call/nodejs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ This code example demonstrates how access can be revoked to decrypt data using `
1111
- Create the Lit Capacity Delegation Auth Sig
1212
- Create the Lit Auth Sig to generate the Session Signatures
1313
- `DEPLOYED_ACCESS_CONTROL_CONTRACT_ADDRESS` - The address of the deployed Access Control Contract
14-
- [The contract](../contracts/src/AccessControl.sol) has been deployed on the Lit Chronicle Yellowstone blockchain at: `0xf960775B87fF2f53Eb962A8845F647615047389E` for testing purposes
14+
- [The contract](../contracts/src/AccessControl.sol) has been deployed on the Lit Chronicle Yellowstone blockchain at: `0x4fc0c02ebbAbb81C04dB0C462C8c25cb37970eB1` for testing purposes
1515
- `LIT_CAPACITY_CREDIT_TOKEN_ID` - The ID of the Lit Capacity Credit Token to avoid minting a new one when the example is ran
1616
3. Run the included tests using `yarn test`

accs-contract-call/nodejs/src/AccessControl.json

Lines changed: 0 additions & 119 deletions
This file was deleted.

accs-contract-call/nodejs/test/index.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ describe("Testing specific functionality", () => {
2323
DEPLOYED_ACCESS_CONTROL_CONTRACT_ADDRESS,
2424
[
2525
{
26-
inputs: [{ internalType: "address", name: "user", type: "address" }],
26+
inputs: [],
2727
name: "grantAccess",
2828
outputs: [],
2929
stateMutability: "nonpayable",
3030
type: "function",
3131
},
3232
{
33-
inputs: [{ internalType: "address", name: "user", type: "address" }],
33+
inputs: [],
3434
name: "revokeAccess",
3535
outputs: [],
3636
stateMutability: "nonpayable",
@@ -41,15 +41,15 @@ describe("Testing specific functionality", () => {
4141
);
4242

4343
it("should decrypt the secret string because access has been granted", async () => {
44-
const tx = await accessControlContract.grantAccess(ethersWallet.address);
44+
const tx = await accessControlContract.grantAccess();
4545
await tx.wait();
4646

4747
const decryptedString = await runExample(SECRET_STRING);
4848
expect(decryptedString).to.equal(SECRET_STRING);
4949
}).timeout(120_000);
5050

5151
it("shouldn't decrypt the secret string because access has been revoked", async () => {
52-
const tx = await accessControlContract.revokeAccess(ethersWallet.address);
52+
const tx = await accessControlContract.revokeAccess();
5353
await tx.wait();
5454

5555
let response;

0 commit comments

Comments
 (0)