Skip to content

Commit

Permalink
chore(@ew-did-registry/proxyidentity): test changeOwner on volta
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiter committed Mar 8, 2021
1 parent 30ec13b commit a4426ba
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 7 deletions.
11 changes: 7 additions & 4 deletions packages/proxyIdentity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"description": "Implementation of contract representing ERC1056 identity",
"main": "dist/src/index.js",
"scripts": {
"compile": "../../node_modules/.bin/tsc",
"test": "../../node_modules/.bin/mocha -r ts-node/register test/**/*.test.ts",
"test-rpc": "run-with-testrpc -m \"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat\" --port 8544 --accounts 20 --networkId=9 --gasLimit=10000000 \"npm run test \" "
"compile": "tsc",
"test-rpc": "run-with-testrpc -m \"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat\" --port 8544 --accounts 20 --networkId=9 --gasLimit=10000000 \"npm run test-ganache \" & npm run test-volta",
"test-ganache": "mocha -r ts-node/register test/offerableidentity.ganache-test.ts",
"test-volta": "mocha -r ts-node/register test/offerableidentity.volta-test.ts"
},
"author": {
"name": "EnergyWeb",
Expand All @@ -22,6 +23,8 @@
"devDependencies": {
"@openzeppelin/contracts": "^2.5.0",
"multi-token-standard": "^0.8.13",
"run-with-testrpc": "0.3.1"
"run-with-testrpc": "0.3.1",
"mocha": "7.1.0",
"typescript": "3.9.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ chai.should();

const { JsonRpcProvider } = providers;

describe.only('[PROXY IDENTITY PACKAGE]', function () {
describe('[PROXY IDENTITY PACKAGE/GANACHE TESTS]', function () {
this.timeout(0);
let identity: Contract;
let erc1056: Contract;
const provider = new JsonRpcProvider('http://localhost:8544');
const creator: providers.JsonRpcSigner = provider.getSigner(0);
const owner = Wallet.createRandom().connect(provider);
const factory = new ContractFactory(proxyAbi, proxyBytecode, creator);
const erc1056Factory = new ContractFactory(abi1056, bytecode1056, creator);
let identityAddr: string;
const id = '123';
const owner = Wallet.createRandom().connect(provider);
const ownerAddr = owner.address;
const ownerKey = new SigningKey(owner.privateKey);

Expand Down Expand Up @@ -58,7 +58,7 @@ describe.only('[PROXY IDENTITY PACKAGE]', function () {
/** Its used only during testing because ganache-cli doesn't conform to Geth eth_sign API
* (https://github.com/trufflesuite/ganache-core/issues/555)
* In production should use
* `const signature = await creator.signMessage(arrayify(hash));`
* `const signature = await owner.signMessage(arrayify(hash));`
*/
const signature = ownerKey.signDigest(arrayify(hash));

Expand Down
82 changes: 82 additions & 0 deletions packages/proxyIdentity/test/offerableidentity.volta-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
Contract, providers, ContractFactory, utils, Wallet,
} from 'ethers';
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { abi as abi1056, bytecode as bytecode1056 } from '../constants/ERC1056.json';
import { abi as proxyAbi, bytecode as proxyBytecode } from '../build/contracts/OfferableIdentity.json';

const {
splitSignature, solidityKeccak256, recoverAddress, arrayify, computeAddress, hexlify
} = utils;

chai.use(chaiAsPromised);
chai.should();

const { JsonRpcProvider } = providers;

describe('[PROXY IDENTITY PACKAGE/VOLTA TESTS]', function () {
this.timeout(0);
let identity: Contract;
let erc1056: Contract;
const provider = new JsonRpcProvider('https://volta-rpc-vkn5r5zx4ke71f9hcu0c.energyweb.org/');
const creator = new Wallet('0x6cb6aba924428d90350b6182fcc091b3ddac52caf9b3a94dc34068e869bad8cf', provider);
const owner = new Wallet('0xa3381acf94ac7c796f55f1499cd18cd11587dac827f873064c7130c286084f10', provider);
const factory = new ContractFactory(proxyAbi, proxyBytecode, creator);
const erc1056Factory = new ContractFactory(abi1056, bytecode1056, creator);
const id = '123';

beforeEach(async () => {
erc1056 = await (await erc1056Factory.deploy()).deployed();
identity = await factory.deploy(id, erc1056.address, owner.address);
});

it('identity creator should be identity owner', async () => {
expect(await erc1056.identityOwner(identity.address)).equal(owner.address);
});

describe('[Identity Transfer]', async () => {
const receiver = new Wallet('0x4bb94bdef5d4175f6c78d969e8ea1399ebd5c24d8dfce56e27f2383caa76eb40', provider);

beforeEach(async () => {
const nonce = await erc1056.nonce(await erc1056.identityOwner(identity.address));

const hash = solidityKeccak256(
['uint8', 'uint8', 'address', 'uint', 'address', 'string', 'address'],
['0x19', '0x00', erc1056.address, nonce, identity.address, 'changeOwner', receiver.address],
);

const signature = await owner.signMessage(arrayify(hash));

const { v, r, s } = splitSignature(signature);

await identity.connect(owner).offer(receiver.address, v, r, s);
});

it.only('Accepting offer should change identity owner', async () => {
await identity.connect(receiver).accept();

expect(await erc1056.identityOwner(identity.address)).equal(receiver.address);
expect(await identity.owner()).equal(receiver.address);
});

it('Rejecting offer should remain identity owner', async () => {
await identity.connect(receiver).reject();

expect(await erc1056.identityOwner(identity.address)).equal(owner.address);
expect(await identity.owner()).equal(owner.address);
});

it('Can\'t accept identity offered to other', async () => {
const nonReceiver = provider.getSigner(3);

return (identity.connect(nonReceiver).accept()).should.be.rejected;
});

it('Can\'t reject identity offered to other', async () => {
const nonReceiver = provider.getSigner(3);

return (identity.connect(nonReceiver).reject()).should.be.rejected;
});
});
});

0 comments on commit a4426ba

Please sign in to comment.