-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding 1155 / Governor and unit test example for 1155 (like a product…
… shop)
- Loading branch information
1 parent
fc098ac
commit 7bc84cf
Showing
20 changed files
with
3,498 additions
and
907 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
{ | ||
"telemetry.enableCrashReporter": false, | ||
|
||
"solidity.remappingsWindows": ["@openzeppelin/contracts/=H:\\JuanFran\\Documents\\Source\\Repos\\Nethereum.ERC721.Template\\node_modules\\@openzeppelin\\contracts"], | ||
"solidity.remappings": ["@openzeppelin/contracts/=H:\\JuanFran\\Documents\\Source\\Repos\\Nethereum.ERC721.Template\\node_modules\\@openzeppelin\\contract"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ERC721ContractLibrary.Contracts.MyERC1155; | ||
using ERC721ContractLibrary.Contracts.MyERC1155.ContractDefinition; | ||
using ERC721ContractLibrary.Contracts.MyERC721; | ||
using ERC721ContractLibrary.Contracts.MyERC721.ContractDefinition; | ||
using Nethereum.Util; | ||
using Nethereum.XUnitEthereumClients; | ||
using Newtonsoft.Json; | ||
using Xunit; | ||
|
||
namespace ERC721ContractLibrary.Testing | ||
{ | ||
[Collection(EthereumClientIntegrationFixture.ETHEREUM_CLIENT_COLLECTION_DEFAULT)] | ||
public class MyErc1155Test | ||
{ | ||
private readonly EthereumClientIntegrationFixture _ethereumClientIntegrationFixture; | ||
|
||
public MyErc1155Test(EthereumClientIntegrationFixture ethereumClientIntegrationFixture) | ||
{ | ||
_ethereumClientIntegrationFixture = ethereumClientIntegrationFixture; | ||
} | ||
|
||
|
||
[Fact] | ||
public async void ShouldDeployAndMintoken() | ||
{ | ||
//Using rinkeby to demo opensea, if we dont want to use the configured client | ||
//please input your infura id in appsettings.test.json | ||
var web3 = _ethereumClientIntegrationFixture.GetInfuraWeb3(InfuraNetwork.Rinkeby); | ||
//var web3 = _ethereumClientIntegrationFixture.GetWeb3(); //if you want to use your local node (ie geth, uncomment this, see appsettings.test.json for further info) | ||
//example of configuration as legacy (not eip1559) to work on L2s | ||
web3.Eth.TransactionManager.UseLegacyAsDefault = true; | ||
|
||
|
||
var ercERC1155Deployment = new MyERC1155Deployment(); | ||
//Deploy the 1155 contract (shop) | ||
var deploymentReceipt = await MyERC1155Service.DeployContractAndWaitForReceiptAsync(web3, ercERC1155Deployment); | ||
|
||
//creating a new service with the new contract address | ||
var erc1155Service = new MyERC1155Service(web3, deploymentReceipt.ContractAddress); | ||
|
||
//uploading to ipfs our documents | ||
var nftIpfsService = new NFTIpfsService("https://ipfs.infura.io:5001"); | ||
var imageIpfs = await nftIpfsService.AddFileToIpfsAsync("ShopImages/hard-drive-by-vincent-botta-from-unsplash.jpg"); | ||
|
||
|
||
//adding all our document ipfs links to the metadata and the description | ||
var metadataNFT = new ProductNFTMetadata() | ||
{ | ||
ProductId = 12131, | ||
Name = "4TB Black Performance Desktop Hard Drive", | ||
Image = "ipfs://" + imageIpfs.Hash, //The image is what is displayed in market places like opean sea | ||
Description = @"Capacity: 4TB | ||
Interface: SATA 6Gb / s | ||
Form Factor: 3.5 Inch | ||
Easy Backup and Upgrade | ||
5 Year Warranty (Photo by: Vincent Botta https://unsplash.com/@0asa)", | ||
ExternalUrl = "https://github.com/Nethereum/ERC721ContractLibrary.Template", | ||
Decimals = 0 | ||
}; | ||
var stockHardDrive = 100; | ||
//Adding the metadata to ipfs | ||
var metadataIpfs = | ||
await nftIpfsService.AddNftsMetadataToIpfsAsync(metadataNFT, metadataNFT.ProductId + ".json"); | ||
|
||
var addressToRegisterOwnership = "0xe612205919814b1995D861Bdf6C2fE2f20cDBd68"; | ||
|
||
//Adding the product information | ||
var tokenUriReceipt = await erc1155Service.SetTokenUriRequestAndWaitForReceiptAsync(metadataNFT.ProductId, | ||
"ipfs://" + metadataIpfs.Hash); | ||
|
||
var mintReceipt = await erc1155Service.MintRequestAndWaitForReceiptAsync(addressToRegisterOwnership, metadataNFT.ProductId, stockHardDrive, new byte[]{}); | ||
|
||
|
||
// the balance should be | ||
var balance = await erc1155Service.BalanceOfQueryAsync(addressToRegisterOwnership, (BigInteger)metadataNFT.ProductId); | ||
|
||
Assert.Equal(stockHardDrive, balance); | ||
|
||
var addressOfToken = await erc1155Service.UriQueryAsync(metadataNFT.ProductId); | ||
|
||
Assert.Equal("ipfs://" + metadataIpfs.Hash, addressOfToken); | ||
|
||
//Url format https://testnets.opensea.io/assets/[nftAddress]/[id] | ||
//opening opensea testnet to visualise the nft | ||
var ps = new ProcessStartInfo("https://testnets.opensea.io/assets/" + deploymentReceipt.ContractAddress + "/" + metadataNFT.ProductId) | ||
{ | ||
UseShellExecute = true, | ||
Verb = "open" | ||
}; | ||
Process.Start(ps); | ||
|
||
//lets sell 2 hard drives | ||
var transfer = await erc1155Service.SafeTransferFromRequestAndWaitForReceiptAsync(addressToRegisterOwnership, addressToRegisterOwnership, (BigInteger)metadataNFT.ProductId, 2, new byte[]{}); | ||
Assert.False(transfer.HasErrors()); | ||
|
||
} | ||
|
||
|
||
public class ProductNFTMetadata : Nft1155Metadata | ||
{ | ||
public int ProductId { get; set; } | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |
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
Binary file added
BIN
+413 KB
...ontractLibrary.Testing/ShopImages/hard-drive-by-vincent-botta-from-unsplash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
617 changes: 0 additions & 617 deletions
617
...ary/ERC721EnumerableUriStorage/ContractDefinition/ERC721EnumerableUriStorageDefinition.cs
This file was deleted.
Oops, something went wrong.
463 changes: 463 additions & 0 deletions
463
ERC721ContractLibrary/MyERC1155/ContractDefinition/MyERC1155Definition.cs
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.