Skip to content
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

Integrate contracts v2.2.0 #1845

Open
wants to merge 51 commits into
base: integration-oasis
Choose a base branch
from

Conversation

mariacarmina
Copy link
Member

@mariacarmina mariacarmina commented Sep 4, 2024

Fixes # .

Changes proposed in this PR:

  • integrated factory contract
  • updated contract version
  • created test script for sapphire

@mariacarmina mariacarmina self-assigned this Sep 4, 2024
Copy link
Member

@alexcos20 alexcos20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comments

export interface AccessListData {
name: string
symbol: string
tokenURI: string[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a typing as NftCreateData is used when creating a NFT.

@@ -41,6 +39,33 @@ export class AccessListContract extends SmartContract {
return await accessListContract.tokenURI()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no function tokenURI without params, so this will never work

const accessListContract = this.getContract(accessListAddress)
return await accessListContract.symbol()
}

/**
* Mint ERC721 contract
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mint new token, or add address to accesslist

it's not minting another erc721 contract

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll modify

@@ -99,6 +124,13 @@ export class AccessListContract extends SmartContract {
return <ReceiptOrEstimate<G>>trxReceipt
}

/**
* Burn Access List
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete address from accessList or burn tokenId

* @return {Promise<string|BigNumber>} The transaction hash or the gas estimate.
*/
public async deployAccessListContract<G extends boolean = false>(
listData: AccessListData,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would advice you to delete that typing (AccessListData) and use function params

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sure.

@@ -70,22 +74,32 @@ export class Nft extends SmartContract {
)
if (estimateGas) return <G extends false ? string : BigNumber>estGas

const addresses = [minter, paymentCollector, mpFeeAddress, feeToken]
if (accessListContract) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only templateID == 4 supports accessLists , so pls make sure that we don't pass it to other template, because those templates might use those fields for something else

providerUrl
)
assert(grapqlOrderTx, 'Ordering graphql dataset failed.')
// arwaveOrderTx = await orderAsset(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why did we removed this tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have commented them for debug because these were failing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, you commented the order , but left the downloads on next tests :) and those are failing without orders..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can focus on this problem, now since I am blocked on testing the integration side.

test/config.ts Outdated
@@ -48,3 +48,16 @@ export const getAddresses = () => {
)
return data.development
}

export const getAddressesForSapphire = (testnet: boolean) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's a good ideea to have two functions:

  • getAddressesForChain(chainID)
  • getAddressesForSapphire which calls getAddressesForChain

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have that locally, not pushed yet.

@alexcos20
Copy link
Member

why for every call to accesslist functions do i need to provide accessListAddress ?

just have it in the constructor and do something like:

accessList = new AccessListContract('0x123')
owner = await accessList.getOwner()

@mariacarmina
Copy link
Member Author

why for every call to accesslist functions do i need to provide accessListAddress ?

just have it in the constructor and do something like:

accessList = new AccessListContract('0x123')
owner = await accessList.getOwner()

It wasn't a specific preference, I can change that AccessList class to extend SmartContractWithAddress class and store the address in constructor. The only reason for using this approach is that Nft class has in each method nft address passed as parameter.

@mariacarmina
Copy link
Member Author

mariacarmina commented Sep 17, 2024

The integration tests for ordering different types of assets is an older issue which pops up due to exceeded timeout. I commented the assets which rely on external services such as ipfs and create an issue for fixing those tests in the future since they are not impacted by this PR changes.

Issue created for ipfs which is the only one impacting the tests due to invalid CID: #1849

Copy link
Member

@jamiehewitt15 jamiehewitt15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the sapphire integration tests in a folder called scripts? Seems like it would be better placed in /test/integration/

.gitignore Outdated
Comment on lines 6 to 7
test/**/*.js
test/unit/*.js
test/integration/*.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you done this? Before we ignored all javascript files in the test directory, now you want only to ignore js files if they are in either /test/unit or test/integration? I don't see any benefit to changing this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was when I created a .js file, I'll correct it now since I have the .ts script, not .js

README.md Outdated
@@ -128,6 +128,21 @@ npm run test:integration
npm run test:integration:cover
```

### Sapphire Integration Tests

Currently, there is used Oasis Sapphire Test network, please export the `PRIVATE_KEY` before testing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worded poorly, I think what you are trying to say is:

Suggested change
Currently, there is used Oasis Sapphire Test network, please export the `PRIVATE_KEY` before testing.
We are currently using the live Oasis Sapphire Test network for the integration tests. Please export the `PRIVATE_KEY` before running the tests.

const provider = sapphire.wrap(
ethers.getDefaultProvider(sapphire.NETWORKS.testnet.defaultGateway)
)
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that these tests are using a private key on a live network, at some point, the wallet address is going to run out of tokens and the tests will fail. Is there some sort fo longer-term plan here, like getting the tests to work with barge? If so, do we have an issue for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the reason that I did not include the tests in the CI, because everytime the account will be drained, we'll have to top up the funds for those. For the moment it's not tested with CI, only locally. We can create an issue for it. @mihaisc suggested to have a separate job which not runs at every push but he said to leave this problem for now, I'll create an issue for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok cool, fair enough

package.json Outdated
@@ -30,6 +30,7 @@
"mocha": "TS_NODE_PROJECT='./test/tsconfig.json' mocha --config=test/.mocharc.json --node-env=test --exit",
"test": "npm run lint && npm run test:unit:cover && npm run test:integration:cover",
"test:unit": "npm run mocha -- 'test/unit/**/*.test.ts'",
"test:sapphire": "npm run mocha -- 'test/scripts/**/*.test.ts'",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move the test file to its proper location /test/integration/
also renaming it to Sapphire.test.ts would be nice
then update the test:saphire to "npm run mocha -- 'test/integration/Sapphire.test.ts'" .. and then just ignore the newloy moved file in the test:integration comand

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sure I can do that.

}

/**
* Add address to access list
* @param {String} user Minter address
* @param {String} tokenUri tokenURI
* @param {Boolean} estimateGas if True, return gas estimate
* @return {Promise<ReceiptOrEstimate>} transactionId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns the transaction receipt

* Delete address from access list
* @param {Number} tokenId token ID
* @param {Boolean} estimateGas if True, return gas estimate
* @return {Promise<ReceiptOrEstimate>} transactionId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return {Promise<ReceiptOrEstimate>} transactionId
* @return {Promise<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value

user,
tokenUri
)
return <ReceiptOrEstimate<G>>trxReceipt
}

/**
* Batch Mint ERC721 contract
* @param {String} accessListAddress AccessList contract address
* Batch add addresses to the access list
* @param {String} users Minter addresses
* @param {String} tokenUris tokenURI
* @param {Boolean} estimateGas if True, return gas estimate
* @return {Promise<ReceiptOrEstimate>} transactionId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return {Promise<ReceiptOrEstimate>} transactionId
* @return {Promise<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value

* Transfer Ownership of an access list, called by owner of access list
* @param {Number} newOwner new owner of the access list
* @param {Boolean} estimateGas if True, return gas estimate
* @return {Promise<ReceiptOrEstimate>} transactionId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return {Promise<ReceiptOrEstimate>} transactionId
* @return {Promise<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value

tokenURI
)
const trxReceipt = await tx.wait()
const events = getEventFromTx(trxReceipt, 'NewAccessList')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the tx fails, need to provide a proper response for the client otherwise the line bellow events.args[0] will fail with uncaught error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the same should be applied in NFTFactory when creating a NFT, try-catch block is missing from there too.

{
...configHelperNetworksBase,
chainId: 23295,
network: 'oasis_saphire_testnet',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is misspelled again, chain name is: oasis_sapphire_testnet

*/
public async getFileObject(
dtAddress: string,
serviceId: number,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to refactor all these occurrences of serviceID (including comments).. It definitely is NOT the service id, but the service index.. so serviceIndex instead, otherwise we get easily confused

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right thing, sure, do that now.


/**
* Create new Access List Contract
* @param {AccessListData} listData The data needed to create an NFT.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets kill this comment about AccessListData :-)

@@ -30,19 +30,23 @@ export class Datatoken4 extends Datatoken {
abi?: AbiItem[]
) {
super(signer, network, config, abi)
this.abi = this.getDefaultAbi()
// Wrap signer's address for encrypted data tx
this.signer = sapphire.wrap(signer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the template only for confidential EVM sapphire?
Cause we're wrapping the signer with their sdk call sapphire.wrap(...) ..
and we have a few functions doing it again like:
confidentialEVM === true ? sapphire.wrap(this.signer) : this.signer, ...
So, we get a "double" wrap() for confidential EVM and a wrap() for any other EVM using this template
For now, i would just remove the wrap() call on the constructor, and later, once we merge the other PR we can refactor this a bit more (from the config we would know if is confidential evm and if we should wrap the calls

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove the wrapper from constructor to avoid confusions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template 4 is only for confidential EVM, I mean, the scope of its creation is destinated for sapphire and files encryption on sapphire chain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants