-
Notifications
You must be signed in to change notification settings - Fork 37
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
Refactor Transaction Watcher #386
Changes from all commits
ab0488b
6710739
6862413
9910946
1206019
a5240ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,11 @@ import { ResultsParser } from "./resultsParser"; | |
import { SmartContract } from "./smartContract"; | ||
import { AddressValue, BigUIntValue, OptionalValue, OptionValue, TokenIdentifierValue, U32Value } from "./typesystem"; | ||
import { BytesValue } from "./typesystem/bytes"; | ||
import { TransactionsFactoryConfig } from "../transactionsFactories/transactionsFactoryConfig"; | ||
import { SmartContractTransactionsFactory } from "../transactionsFactories/smartContractTransactionsFactory"; | ||
import { TokenComputer } from "../tokens"; | ||
import { promises } from "fs"; | ||
import { TransactionComputer } from "../transaction"; | ||
|
||
describe("test on local testnet", function () { | ||
let alice: TestWallet, bob: TestWallet, carol: TestWallet; | ||
|
@@ -85,12 +90,12 @@ describe("test on local testnet", function () { | |
await provider.sendTransaction(transactionDeploy); | ||
await provider.sendTransaction(transactionIncrement); | ||
|
||
await watcher.awaitCompleted(transactionDeploy); | ||
await watcher.awaitCompleted(transactionDeploy.getHash().hex()); | ||
let transactionOnNetwork = await provider.getTransaction(transactionDeploy.getHash().hex()); | ||
let bundle = resultsParser.parseUntypedOutcome(transactionOnNetwork); | ||
assert.isTrue(bundle.returnCode.isSuccess()); | ||
|
||
await watcher.awaitCompleted(transactionIncrement); | ||
await watcher.awaitCompleted(transactionIncrement.getHash().hex()); | ||
transactionOnNetwork = await provider.getTransaction(transactionIncrement.getHash().hex()); | ||
bundle = resultsParser.parseUntypedOutcome(transactionOnNetwork); | ||
assert.isTrue(bundle.returnCode.isSuccess()); | ||
|
@@ -150,9 +155,9 @@ describe("test on local testnet", function () { | |
await provider.sendTransaction(transactionIncrementFirst); | ||
await provider.sendTransaction(transactionIncrementSecond); | ||
|
||
await watcher.awaitCompleted(transactionDeploy); | ||
await watcher.awaitCompleted(transactionIncrementFirst); | ||
await watcher.awaitCompleted(transactionIncrementSecond); | ||
await watcher.awaitCompleted(transactionDeploy.getHash().hex()); | ||
await watcher.awaitCompleted(transactionIncrementFirst.getHash().hex()); | ||
await watcher.awaitCompleted(transactionIncrementSecond.getHash().hex()); | ||
|
||
// Check counter | ||
let query = contract.createQuery({ func: new ContractFunction("get") }); | ||
|
@@ -212,9 +217,9 @@ describe("test on local testnet", function () { | |
await provider.sendTransaction(transactionMintBob); | ||
await provider.sendTransaction(transactionMintCarol); | ||
|
||
await watcher.awaitCompleted(transactionDeploy); | ||
await watcher.awaitCompleted(transactionMintBob); | ||
await watcher.awaitCompleted(transactionMintCarol); | ||
await watcher.awaitCompleted(transactionDeploy.getHash().hex()); | ||
await watcher.awaitCompleted(transactionMintBob.getHash().hex()); | ||
await watcher.awaitCompleted(transactionMintCarol.getHash().hex()); | ||
|
||
// Query state, do some assertions | ||
let query = contract.createQuery({ func: new ContractFunction("totalSupply") }); | ||
|
@@ -294,8 +299,8 @@ describe("test on local testnet", function () { | |
await provider.sendTransaction(transactionDeploy); | ||
await provider.sendTransaction(transactionStart); | ||
|
||
await watcher.awaitAllEvents(transactionDeploy, ["SCDeploy"]); | ||
await watcher.awaitAnyEvent(transactionStart, ["completedTxEvent"]); | ||
await watcher.awaitAllEvents(transactionDeploy.getHash().hex(), ["SCDeploy"]); | ||
await watcher.awaitAnyEvent(transactionStart.getHash().hex(), ["completedTxEvent"]); | ||
|
||
// Let's check the SCRs | ||
let transactionOnNetwork = await provider.getTransaction(transactionDeploy.getHash().hex()); | ||
|
@@ -325,4 +330,51 @@ describe("test on local testnet", function () { | |
queryResponse = await provider.queryContract(query); | ||
assert.equal(decodeUnsignedNumber(queryResponse.getReturnDataParts()[0]), 0); | ||
}); | ||
|
||
it("counter: should deploy and call using the SmartContractFactory", async function () { | ||
this.timeout(80000); | ||
|
||
TransactionWatcher.DefaultPollingInterval = 5000; | ||
TransactionWatcher.DefaultTimeout = 50000; | ||
|
||
const network = await provider.getNetworkConfig(); | ||
await alice.sync(provider); | ||
|
||
const transactionComputer = new TransactionComputer(); | ||
const config = new TransactionsFactoryConfig(network.ChainID); | ||
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. Now I see - we should pass init parameters to This would be for another, separate PR. 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. Will do in the next PR. |
||
const factory = new SmartContractTransactionsFactory({ config: config, tokenComputer: new TokenComputer() }); | ||
|
||
let bytecode = await promises.readFile("src/testdata/counter.wasm"); | ||
|
||
const deployTransaction = factory.createTransactionForDeploy({ | ||
sender: alice.address, | ||
bytecode: bytecode, | ||
gasLimit: 3000000n, | ||
}); | ||
deployTransaction.nonce = BigInt(alice.account.nonce.valueOf()); | ||
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. A bit verbose, but good at this moment. In the cookbook I think we will not mention |
||
deployTransaction.signature = await alice.signer.sign( | ||
Buffer.from(transactionComputer.computeBytesForSigning(deployTransaction)), | ||
); | ||
|
||
const deployTxHash = await provider.sendTransaction(deployTransaction); | ||
await watcher.awaitCompleted(deployTxHash); | ||
|
||
const contractAddress = SmartContract.computeAddress(alice.address, alice.account.nonce); | ||
|
||
alice.account.incrementNonce(); | ||
|
||
const smartContractCallTransaction = factory.createTransactionForExecute({ | ||
sender: alice.address, | ||
contract: contractAddress, | ||
functionName: "increment", | ||
gasLimit: 2000000n, | ||
}); | ||
smartContractCallTransaction.nonce = BigInt(alice.account.nonce.valueOf()); | ||
smartContractCallTransaction.signature = await alice.signer.sign( | ||
Buffer.from(transactionComputer.computeBytesForSigning(smartContractCallTransaction)), | ||
); | ||
|
||
const scCallTxHash = await provider.sendTransaction(smartContractCallTransaction); | ||
await watcher.awaitCompleted(scCallTxHash); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,8 @@ describe("fetch transactions from local testnet", function () { | |
await provider.sendTransaction(transactionDeploy); | ||
await provider.sendTransaction(transactionIncrement); | ||
|
||
await watcher.awaitCompleted(transactionDeploy); | ||
await watcher.awaitCompleted(transactionIncrement); | ||
await watcher.awaitCompleted(transactionDeploy.getHash().hex()); | ||
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. In a future PR, we should also adjust the integration tests to use the transaction factories for deploy, call etc. |
||
await watcher.awaitCompleted(transactionIncrement.getHash().hex()); | ||
|
||
let transactionOnNetworkDeploy = await provider.getTransaction(transactionDeploy.getHash().hex()); | ||
let transactionOnNetworkIncrement = await provider.getTransaction(transactionIncrement.getHash().hex()); | ||
|
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.
🚀 👍 (in relation to the other comment about a next PR for integration tests, only now I see this test)