-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: e2e tests #245
base: feat/token-registry-v4
Are you sure you want to change the base?
feat: e2e tests #245
Changes from 18 commits
bef0e59
6bcaf9c
fce3481
a8d573a
6d53ef4
d4995ed
4799fea
1a2c734
4fc6793
3a61c96
6a4313d
a5973f2
c2cda9e
530cb40
82b228e
2e5c66a
a6639c5
e6bd493
a070e2c
0c823f5
49137d7
b195ad7
2504499
bd75393
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { | ||
checkFailure, | ||
checkSurrenderAcceptSuccess, | ||
deployTokenRegistry, | ||
mintSurrenderToken, | ||
mintTokenRegistry, | ||
} from "./utils/helpers"; | ||
import { generateAcceptSurrenderCommand } from "./utils/commands"; | ||
import { BurnAddress, defaultRunParameters, EmptyTokenID, owner, receiver } from "./utils/constants"; | ||
import { getSigner, retrieveTitleEscrowOwner } from "./utils/contract-checks"; | ||
import { run } from "./utils/shell"; | ||
|
||
export const acceptSurrender = async (): Promise<void> => { | ||
const tokenRegistryAddress = deployTokenRegistry(owner.privateKey); | ||
// const errors: Error[] = []; | ||
const defaultTitleEscrow = { | ||
...defaultRunParameters, | ||
beneficiary: owner.ethAddress, | ||
holder: owner.ethAddress, | ||
}; | ||
|
||
//"should be able to accept-surrender title-escrow on token-registry" | ||
{ | ||
const { tokenRegistry, tokenId } = mintSurrenderToken(owner.privateKey, tokenRegistryAddress); | ||
const command = generateAcceptSurrenderCommand({ tokenRegistry, tokenId, ...defaultTitleEscrow }, owner.privateKey); | ||
const signer = await getSigner(defaultTitleEscrow.network, owner.privateKey); | ||
let titleEscrowOwner: string = await retrieveTitleEscrowOwner(signer, tokenRegistry, tokenId); | ||
if (!(titleEscrowOwner === tokenRegistry)) throw new Error(`!(titleEscrowOwner === tokenRegistry)`); | ||
|
||
const results = run(command); | ||
titleEscrowOwner = await retrieveTitleEscrowOwner(signer, tokenRegistry, tokenId); | ||
if (!(titleEscrowOwner === "0x000000000000000000000000000000000000dEaD")) | ||
throw new Error(`!(titleEscrowOwner === "0x000000000000000000000000000000000000dEaD")`); | ||
checkSurrenderAcceptSuccess(results); | ||
} | ||
|
||
//"should not be able to accept surrender invalid title-escrow on token-registry" | ||
{ | ||
const { tokenRegistry } = mintSurrenderToken(owner.privateKey, tokenRegistryAddress); | ||
const command = generateAcceptSurrenderCommand( | ||
{ tokenRegistry, tokenId: EmptyTokenID, ...defaultTitleEscrow }, | ||
owner.privateKey | ||
); | ||
const results = run(command); | ||
checkFailure(results, "Unminted Token"); | ||
} | ||
|
||
//"should not be able to accept surrender title-escrow on invalid token-registry" | ||
{ | ||
const { tokenId } = mintSurrenderToken(owner.privateKey, tokenRegistryAddress); | ||
const command = generateAcceptSurrenderCommand( | ||
{ tokenRegistry: BurnAddress, tokenId, ...defaultTitleEscrow }, | ||
owner.privateKey | ||
); | ||
const results = run(command); | ||
checkFailure(results, `Address ${BurnAddress} is not a valid Contract`); | ||
} | ||
|
||
//"should not be able to accept un-owned/held surrendered title-escrow on invalid token-registry" | ||
{ | ||
const { tokenId } = mintSurrenderToken(owner.privateKey, tokenRegistryAddress); | ||
const command = generateAcceptSurrenderCommand( | ||
{ tokenRegistry: tokenRegistryAddress, tokenId, ...defaultTitleEscrow }, | ||
receiver.privateKey | ||
); | ||
const results = run(command); | ||
checkFailure(results, "Wallet lack the rights for the transfer operation"); | ||
} | ||
|
||
//"should not be able to accept un-surrendered title-escrow on token-registry" | ||
{ | ||
const { tokenId } = mintTokenRegistry(owner.privateKey, tokenRegistryAddress); | ||
const command = generateAcceptSurrenderCommand( | ||
{ tokenRegistry: tokenRegistryAddress, tokenId, ...defaultTitleEscrow }, | ||
owner.privateKey | ||
); | ||
const results = run(command); | ||
checkFailure(results, "Title Escrow has not been surrendered"); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { acceptSurrender } from "./accept-surrender.e2e"; | ||
import { surrender } from "./surrender.e2e"; | ||
import { changeHolder } from "./change-holder.e2e"; | ||
import { deployDocumentStore, deployTokenRegistry } from "./deploy.e2e"; | ||
import { endorseTransfer } from "./endorse-transfer.e2e"; | ||
import { mint } from "./mint.e2e"; | ||
import { nominate } from "./nominate.e2e"; | ||
import { rejectSurrender } from "./reject-surrender.e2e"; | ||
import { endorseChangeOwner } from "./endorse-change-owner.e2e"; | ||
|
||
const awaitForDuration = async (runFunction: () => void): Promise<void> => { | ||
await runFunction(); | ||
console.log(runFunction.name); | ||
}; | ||
|
||
awaitForDuration(deployDocumentStore); | ||
awaitForDuration(deployTokenRegistry); | ||
|
||
awaitForDuration(mint); | ||
|
||
awaitForDuration(surrender); | ||
awaitForDuration(rejectSurrender); | ||
awaitForDuration(acceptSurrender); | ||
|
||
awaitForDuration(nominate); | ||
awaitForDuration(changeHolder); | ||
awaitForDuration(endorseChangeOwner); | ||
awaitForDuration(endorseTransfer); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import { TitleEscrowTransferHolderCommand } from "../commands/title-escrow/title-escrow-command.type"; | ||
import { | ||
changeHolderToken, | ||
checkChangeHolderSuccess, | ||
checkFailure, | ||
defaultTransferHolder, | ||
deployTokenRegistry, | ||
mintBurntToken, | ||
mintSurrenderToken, | ||
mintTokenRegistry, | ||
} from "./utils/helpers"; | ||
import { generateChangeHolderCommand } from "./utils/commands"; | ||
import { BurnAddress, EmptyTokenID, owner, receiver } from "./utils/constants"; | ||
import { run } from "./utils/shell"; | ||
import { getSigner, retrieveTitleEscrow } from "./utils/contract-checks"; | ||
import { BigNumber } from "ethers"; | ||
|
||
// "transfer holder title-escrow" | ||
export const changeHolder = async (): Promise<void> => { | ||
const tokenRegistryAddress = deployTokenRegistry(owner.privateKey); | ||
|
||
//should be able to transfer holder title-escrow on token-registry" | ||
{ | ||
const { tokenRegistry, tokenId } = mintTokenRegistry(owner.privateKey, tokenRegistryAddress); | ||
const transferHolder: TitleEscrowTransferHolderCommand = { | ||
tokenId: tokenId, | ||
tokenRegistry: tokenRegistry, | ||
...defaultTransferHolder, | ||
}; | ||
const command = generateChangeHolderCommand(transferHolder, owner.privateKey); | ||
const results = run(command); | ||
checkChangeHolderSuccess(results); | ||
|
||
const signer = await getSigner(transferHolder.network, receiver.privateKey); | ||
const titleEscrowInfo = await retrieveTitleEscrow(signer, transferHolder.tokenRegistry, transferHolder.tokenId); | ||
if (!(titleEscrowInfo.active === true)) throw new Error(`titleEscrowInfo.active === true`); | ||
if (!(titleEscrowInfo.holder === transferHolder.newHolder)) | ||
throw new Error(`titleEscrowInfo.holder === transferHolder.holder`); | ||
if (!(titleEscrowInfo.isHoldingToken === true)) throw new Error(`titleEscrowInfo.isHoldingToken === true`); | ||
if (!(titleEscrowInfo.nominee === BurnAddress)) throw new Error(`titleEscrowInfo.nominee === BurnAddress`); | ||
if (!(titleEscrowInfo.registry === transferHolder.tokenRegistry)) | ||
throw new Error(`titleEscrowInfo.registry === transferHolder.address`); | ||
const correctTokenID = titleEscrowInfo.tokenId.eq(BigNumber.from(transferHolder.tokenId)); | ||
if (!(correctTokenID === true)) throw new Error(`correctTokenID === true`); | ||
} | ||
|
||
//holder should be able to transfer holder of title-escrow" | ||
{ | ||
const { tokenRegistry, tokenId } = mintTokenRegistry(owner.privateKey, tokenRegistryAddress); | ||
// Transfer Holder to Receiver | ||
const initialHolder: TitleEscrowTransferHolderCommand = { | ||
...defaultTransferHolder, | ||
tokenId: tokenId, | ||
tokenRegistry: tokenRegistry, | ||
newHolder: receiver.ethAddress, | ||
}; | ||
changeHolderToken(owner.privateKey, initialHolder); | ||
// Transfer Holder to Receiver | ||
// Holder attempts to transfer Holder with permission | ||
const transferHolder: TitleEscrowTransferHolderCommand = { | ||
...defaultTransferHolder, | ||
tokenId: tokenId, | ||
tokenRegistry: tokenRegistry, | ||
newHolder: owner.ethAddress, | ||
}; | ||
const command = generateChangeHolderCommand(transferHolder, receiver.privateKey); | ||
// Holder attempts to transfer Holder with permission | ||
const results = run(command); | ||
checkChangeHolderSuccess(results); | ||
} | ||
|
||
//should not be able to transfer holder of invalid title-escrow on token-registry" | ||
{ | ||
const { tokenRegistry } = mintTokenRegistry(owner.privateKey, tokenRegistryAddress); | ||
const transferHolder: TitleEscrowTransferHolderCommand = { | ||
tokenId: EmptyTokenID, | ||
tokenRegistry: tokenRegistry, | ||
...defaultTransferHolder, | ||
}; | ||
const command = generateChangeHolderCommand(transferHolder, owner.privateKey); | ||
const results = run(command); | ||
checkFailure(results, "Unminted Token"); | ||
} | ||
|
||
//should not be able to transfer holder of title-escrow on invalid token-registry" | ||
{ | ||
const { tokenId } = mintTokenRegistry(owner.privateKey, tokenRegistryAddress); | ||
const transferHolder: TitleEscrowTransferHolderCommand = { | ||
tokenId: tokenId, | ||
tokenRegistry: BurnAddress, | ||
...defaultTransferHolder, | ||
}; | ||
const command = generateChangeHolderCommand(transferHolder, owner.privateKey); | ||
const results = run(command); | ||
checkFailure(results, `Address ${BurnAddress} is not a valid Contract`); | ||
} | ||
|
||
//beneficiary should not be able to transfer holder of title-escrow" | ||
{ | ||
const { tokenRegistry, tokenId } = mintTokenRegistry(owner.privateKey, tokenRegistryAddress); | ||
// Transfer Holder to Receiver | ||
const initialHolder: TitleEscrowTransferHolderCommand = { | ||
...defaultTransferHolder, | ||
tokenId: tokenId, | ||
tokenRegistry: tokenRegistry, | ||
newHolder: receiver.ethAddress, | ||
}; | ||
changeHolderToken(owner.privateKey, initialHolder); | ||
// Transfer Holder to Receiver | ||
// Beneficiary attempts to transfer Holder without permission | ||
const transferHolder: TitleEscrowTransferHolderCommand = { | ||
...defaultTransferHolder, | ||
tokenId: tokenId, | ||
tokenRegistry: tokenRegistry, | ||
newHolder: owner.ethAddress, | ||
}; | ||
const command = generateChangeHolderCommand(transferHolder, owner.privateKey); | ||
// Beneficiary attempts to transfer Holder without permission | ||
const results = run(command); | ||
checkFailure(results, "Wallet lack the rights for the transfer operation"); | ||
} | ||
|
||
// should not be able to transfer holder of surrendered title-escrow" | ||
{ | ||
const { tokenRegistry, tokenId } = mintSurrenderToken(owner.privateKey, tokenRegistryAddress); | ||
const transferHolder: TitleEscrowTransferHolderCommand = { | ||
...defaultTransferHolder, | ||
tokenId: tokenId, | ||
tokenRegistry: tokenRegistry, | ||
newHolder: owner.ethAddress, | ||
}; | ||
const command = generateChangeHolderCommand(transferHolder, owner.privateKey); | ||
const results = run(command); | ||
checkFailure(results, "Title Escrow has already been surrendered"); | ||
} | ||
|
||
//should not be able to transfer holder of burnt title-escrow" | ||
{ | ||
const { tokenRegistry, tokenId } = mintBurntToken(owner.privateKey, tokenRegistryAddress); | ||
const transferHolder: TitleEscrowTransferHolderCommand = { | ||
...defaultTransferHolder, | ||
tokenId: tokenId, | ||
tokenRegistry: tokenRegistry, | ||
newHolder: owner.ethAddress, | ||
}; | ||
const command = generateChangeHolderCommand(transferHolder, owner.privateKey); | ||
const results = run(command); | ||
checkFailure(results, "Title Escrow has already been shredded"); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { run } from "./utils/shell"; | ||
import { DeployDocumentStoreCommand, DeployTokenRegistryCommand } from "../commands/deploy/deploy.types"; | ||
import { isAddress } from "web3-utils"; | ||
import { defaultRunParameters, EndStatus, owner } from "./utils/constants"; | ||
import { generateDeployDocumentStoreCommand, generateDeployTokenRegistryCommand } from "./utils/commands"; | ||
import { getSigner, retrieveTokenInfo, rolesCheck } from "./utils/contract-checks"; | ||
import { checkTokenRegistrySuccess, defaultTokenRegistry } from "./utils/helpers"; | ||
|
||
export const deployTokenRegistry = async (): Promise<void> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can add a suffixes to indicate its a e2e test? |
||
//should be able to deploy token-registry" | ||
{ | ||
const tokenRegistryParameter: DeployTokenRegistryCommand = { | ||
registryName: "Test Token", | ||
registrySymbol: "TKN", | ||
...defaultTokenRegistry, | ||
}; | ||
|
||
const command = generateDeployTokenRegistryCommand(tokenRegistryParameter, owner.privateKey); | ||
const results = run(command); | ||
const tokenRegistryAddress = checkTokenRegistrySuccess(results); | ||
const signer = getSigner(defaultRunParameters.network, owner.privateKey); | ||
const tokenInfo = await retrieveTokenInfo(signer, tokenRegistryAddress); | ||
if (!(tokenInfo.name === tokenRegistryParameter.registryName)) { | ||
throw new Error("tokenInfo.name === tokenRegistryParameter.registryName"); | ||
} | ||
if (!(tokenInfo.symbol === tokenRegistryParameter.registrySymbol)) { | ||
throw new Error("tokenInfo.symbol === tokenRegistryParameter.registrySymbol"); | ||
} | ||
Comment on lines
+22
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. y do we need to check for the name and symbol, when those are the parameters you specified? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's checking the values on the deployed token-registry rather than within oa-cli, not necessary but is of some use in case something is seriously broken on the smart contract level |
||
const rolesInfo = await rolesCheck(signer, tokenRegistryAddress); | ||
if (!(rolesInfo.accepterRole === true)) { | ||
throw new Error("rolesInfo.accepterRole === true"); | ||
} | ||
if (!(rolesInfo.defaultRole === true)) { | ||
throw new Error("rolesInfo.defaultRole === true"); | ||
} | ||
if (!(rolesInfo.minterRole === true)) { | ||
throw new Error("rolesInfo.minterRole === true"); | ||
} | ||
if (!(rolesInfo.restorerRole === true)) { | ||
throw new Error("rolesInfo.restorerRole === true"); | ||
} | ||
} | ||
}; | ||
|
||
export const deployDocumentStore = async (): Promise<void> => { | ||
//should be able to deploy document-store | ||
{ | ||
const documentStoreParameters: DeployDocumentStoreCommand = { | ||
storeName: "Test Document Store", | ||
...defaultRunParameters, | ||
}; | ||
|
||
const command = generateDeployDocumentStoreCommand(documentStoreParameters, owner.privateKey); | ||
const results = run(command); | ||
const tokenRegistrySuccessFormat = `${EndStatus.success} Document store Test Document Store deployed at `; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mistake? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the document store is called |
||
const checkSuccess = results.includes(tokenRegistrySuccessFormat); | ||
if (!(checkSuccess === true)) throw new Error(`checkSuccess === true)`); | ||
const splitResults = results.trim().split("\n"); | ||
const tokenRegistryAddressLine = splitResults[splitResults.length - 2]; | ||
const tokenRegistryAddress = tokenRegistryAddressLine.trim().substring(tokenRegistrySuccessFormat.length); | ||
if (!(isAddress(tokenRegistryAddress) === true)) throw new Error(`isAddress(tokenRegistryAddress) === true)`); | ||
if (!(isAddress(tokenRegistryAddress) === true)) { | ||
throw new Error("isAddress(tokenRegistryAddress) === true"); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name this file index better