Skip to content

Commit

Permalink
update readme & small rfk
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Dec 4, 2022
1 parent 9060510 commit 388ac2f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const foobarFacet = (await ethers.getContractAt('FoobarFacet', diamondAddress))

Although you are connected to the `Diamond` contract, the calldata will be formed according to `FoobardFacet` which will cause them to fall into the `fallback` at the diamond, and be routed accordingly.

This repository is complementary to my blog post: ...
This repository is complementary to my blog post: <https://dev.to/erhant/how-to-use-typescript-with-eip-2535-diamonds-3gl6>

## Usage

Expand All @@ -25,4 +25,3 @@ This repository is complementary to my blog post: ...

- TypeScript codes are formatted & linted with [GTS](https://github.com/google/gts).
- Contracts are formatted with [Solidity + Hardhat](https://hardhat.org/hardhat-vscode/docs/formatting).
- Contracts are linted with [solhint](https://protofire.github.io/solhint).
7 changes: 1 addition & 6 deletions scripts/Diamond.deploy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {ethers} from 'hardhat';
import constants from '../constants';
import {FacetCutAction} from '../types/facetCut';
import {IDiamondCut} from '../types/typechain';
import {cutDiamond} from './Diamond.cut';

export enum FacetCutAction {
Add = 0,
Replace = 1,
Remove = 2,
}

/**
* Deploys a diamond contract.
* @param ownerAddress contract owner
Expand Down
30 changes: 14 additions & 16 deletions test/Diamond.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ import {expect} from 'chai';
import {ethers} from 'hardhat';
import constants from '../constants';
import {cutDiamond} from '../scripts/Diamond.cut';
import {
deployDiamondCutFacet,
deployFacet,
deployDiamond,
deployDiamondInit,
FacetCutAction,
} from '../scripts/Diamond.deploy';
import {deployDiamondCutFacet, deployFacet, deployDiamond, deployDiamondInit} from '../scripts/Diamond.deploy';
import {FacetCutAction} from '../types/facetCut';
import {IDiamondCut, OwnershipFacet} from '../types/typechain';
import {FoobarFacet} from '../types/typechain/facets/FoobarFacet';

Expand Down Expand Up @@ -70,36 +65,39 @@ describe('Diamond', async () => {

// cut the diamond to register facets at the diamond
// test each facet independently from that point on
it('should upgrade diamond via DiamondCutFacet', async () => {
it('should upgrade Diamond via DiamondCutFacet', async () => {
await cutDiamond(diamondAddress, diamondInitAddress, facetCuts);
});
});

describe('Ownership facet', async () => {
describe('OwnershipFacet', async () => {
let ownershipFacet: OwnershipFacet;
before(async () => {
// sometimes, you dont' even need to cast typechain overloads the getContractAt within hardhat
ownershipFacet = await ethers.getContractAt('OwnershipFacet', diamondAddress);
});

it('should give the correct owner', async () => {
it('should have the correct owner', async () => {
const [owner] = await ethers.getSigners();
expect(await ownershipFacet.owner()).to.be.eq(owner.address);
});
});

describe('Foobar facet', async () => {
describe('FoobarFacet', async () => {
let foobarFacet: FoobarFacet;
let foobarFacetAddress: string;
before(async () => {
// you can cast to the connected facet to use its functions
foobarFacet = (await ethers.getContractAt('FoobarFacet', diamondAddress)) as FoobarFacet;
foobarFacetAddress = facetNameToAddress['FoobarFacet'];
});

it('should respond to `callMe`', async () => {
await expect(foobarFacet.callMe(5)).to.emit(foobarFacet, 'WasCalled').withArgs(owner.address, 5);
it('should be able to call `callMe`', async () => {
const number = 5;
await expect(foobarFacet.callMe(number)).to.emit(foobarFacet, 'WasCalled').withArgs(owner.address, number);
});

it('should be able ot call `removeMe`', async () => {
it('should be able to call `removeMe`', async () => {
await expect(foobarFacet.removeMe()).to.revertedWith('FoobarFacet: you should have removed me :)');
});

Expand All @@ -126,7 +124,7 @@ describe('Diamond', async () => {
diamondAddress,
[
{
facetAddress: facetNameToAddress['FoobarFacet'],
facetAddress: foobarFacetAddress,
action: FacetCutAction.Add,
functionSelectors: [foobarFacet.interface.getSighash('removeMe()')],
},
Expand All @@ -147,7 +145,7 @@ describe('Diamond', async () => {
diamondAddress,
[
{
facetAddress: facetNameToAddress['FoobarFacet'],
facetAddress: foobarFacetAddress,
action: FacetCutAction.Replace,
functionSelectors: [foobarFacet.interface.getSighash('supportsInterface(bytes4)')],
},
Expand Down
5 changes: 5 additions & 0 deletions types/facetCut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum FacetCutAction {
Add = 0,
Replace = 1,
Remove = 2,
}

0 comments on commit 388ac2f

Please sign in to comment.