Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Sep 11, 2023
1 parent f0e1911 commit cf59675
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"scripts": {
"build": "npx hardhat compile && bash extract-abis.bash",
"test": "scripts/test test/contract.test.ts",
"test": "scripts/test test/*.test.ts",
"deploy-local": "npx hardhat run scripts/deploy.ts --network localhost | tee contract-deployment.json"
},
"dependencies": {},
Expand Down
76 changes: 76 additions & 0 deletions contracts/test/registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import '@nomicfoundation/hardhat-chai-matchers';

import {expect} from 'chai';
import * as deployment from '../utils/deploy';
import {getAccounts, Account, toGRT} from '../utils/helpers';

import {Registry, EntryStructOutput} from '../types/contracts/Registry';
import {BigNumber} from 'ethers';
import {setAutoMine} from './helpers';

describe('Registry contract', () => {
// Accounts
let deployer: Account;
let other: Account;

// Contracts
let registry: Registry;

before(async function () {
[deployer, other] = await getAccounts();

setAutoMine(true);
});

beforeEach(async function () {
registry = await deployment.deployRegistry(deployer.signer, false);
});

describe('constructor', function () {
it('should set the owner to the contract deployer address', async function () {
expect(await registry.owner()).to.eq(deployer.address);
});
});

describe('transferOwnership', function () {
it('should set the owner to the new owner', async function () {
await registry.transferOwnership(other.address);
expect(await registry.owner()).to.eq(other.address);
});
});

describe('insertEntry', function () {
it('should set entry', async function () {
const entryID = BigNumber.from(1);
const entry = {
subscriptions: [
'0x0000000000000000000000000000000000000001',
'0x0000000000000000000000000000000000000002',
],
metadataHash:
'0x0000000000000000000000000000000000000000000000000000000000000001',
};
await registry.insertEntry(entryID, entry);
const entry_ = await registry.entries(entryID);
console.log({entry_});
expect(await registry.entries(entryID)).to.eq(entry);
});

// it('should overwrite entry', async function () {
// // TODO
// });
});

// describe('removeEntry', function () {
// it('should remove entry', async function () {
// const entryID = BigNumber.from(1);
// const subscriptions = ["0x0000000000000000000000000000000000000001"];
// const metadataHash = "0x0000000000000000000000000000000000000000000000000000000000000001";
// await registry.insertEntry(entryID, {subscriptions, metadataHash});
// // await registry.removeEntry(entryID);
// const entries = await registry.entries(entryID);
// console.log({ entries });
// // expect(await registry.entries()).to.eq(subscriptionsOwner1.address);
// });
// });
});
11 changes: 9 additions & 2 deletions contracts/utils/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Artifacts } from 'hardhat/internal/artifacts'
import { LinkReferences } from 'hardhat/types'

import { Subscriptions } from '../types/contracts/Subscriptions'
import { StableToken } from '../types'
import { Registry, StableToken } from '../types'

type Abi = Array<string | utils.FunctionFragment | utils.EventFragment | utils.ParamType>

Expand Down Expand Up @@ -71,4 +71,11 @@ export async function deployStableToken(
logging = true
): Promise<StableToken> {
return deployContract(args, sender, 'StableToken', logging) as unknown as Promise<StableToken>
}
}

export async function deployRegistry(
sender: Signer,
logging = true
): Promise<Registry> {
return deployContract([], sender, 'Registry', logging) as unknown as Promise<Registry>
}

0 comments on commit cf59675

Please sign in to comment.