-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(@ew-did-registry/proxyidentity): test changeOwner on volta
- Loading branch information
Showing
3 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/proxyIdentity/test/offerableidentity.volta-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); | ||
}); |