Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Adds feature and updates testing API #8

Closed
wants to merge 21 commits into from
Closed

Conversation

10thfloor
Copy link
Contributor

@10thfloor 10thfloor commented Jan 7, 2021

The aim of this work is to simplify working with Cadence in testing scenarios. Building on the great foundation laid by @MaxStalker

TODO:

  • Example tests
  • Arguments to tx and contract init() functions

Highlights of this PR:
Loading Cadence files. Once configured, flow-js-testing can load Cadence files by name

const NFTContract = await contract("NonFungibleToken");
const FTContract = await contract("FungibleToken");
const MarketplaceContract = await contract("MarketPlace);

const tx1 = await tx("tx_01_check_nft");
const tx2 = await tx("tx_02_configure_user_account");

const script1 = await script("check_balance")

Simple API to create accounts for testing purposes. Users can create a Flow account, and alias it for lookup later. In this case, If an account named "Bob" already exists, it returns the account.

let Bob = account("Bob")
let Alice = account("Bob")

Explicit functions for updating protocol state

Bob = await F.createAccount(Bob) // Bob is now a 'DeployedAccount' object

const DeployedNFTContract = await F.deployContract(Bob, NFTContract)
const DeployedFTContract = await F.deployContract(Alice, FTContract)
const DeployedMarketplaceContract = await F.deployContract(Alice, MarketplaceContract)

const txResult = await F.sendTx(tx1)

F.addBalance(Bob, 200);
F.addBalance(Alice, 200)

Easily replace imports (Done before execution / deployment)

tx1.importing({
   NonFungibleToken: DeployedNFTContract.address,
});

tx1.replace({
      "getAccount(0x01)": `getAccount(${Bob.address})`, // can also use regex replace
});

tx1.signers(Bob.address);

script1.importing({
   FungibleToken: DeployedFTContract.address
})

MarketplaceContract.importing({
  NonFungibleToken: DeployedNFTContract.address,
  FungibleToken: DeployedFTContract.address
})

@10thfloor 10thfloor linked an issue Jan 15, 2021 that may be closed by this pull request
@ericc572
Copy link

any updates as to when this will be merged? we are starting to test soon

@10thfloor
Copy link
Contributor Author

Closing because these changes have been superseded by: #16 - #22 et. al.

@10thfloor 10thfloor closed this May 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flow-JS Testing Examples & Documentation
2 participants