-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new static method to
contract.Client
to deploy & construct co…
…ntracts (#1086) This will allow using a wasm hash and constructor args to create an assembled transaction that will deploy and initialize a contract. Generated types in the CLI are to follow. Co-authored-by: Elliot Voris <[email protected]> Co-authored-by: Chad Ostrowski <[email protected]> Co-authored-by: Elliot Voris <[email protected]>
- Loading branch information
1 parent
cfea8de
commit 40d1497
Showing
8 changed files
with
267 additions
and
80 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
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
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,58 @@ | ||
const { expect } = require("chai"); | ||
const { contract } = require("../../../lib"); | ||
const { installContract, rpcUrl, networkPassphrase } = require("./util"); | ||
const { basicNodeSigner } = require("../../../lib/contract"); | ||
|
||
const INIT_VALUE = 42; | ||
|
||
describe("contract with constructor args", function () { | ||
before(async function () { | ||
const { wasmHash, keypair } = await installContract("increment"); | ||
this.context = { wasmHash, keypair }; | ||
}); | ||
|
||
it("can be instantiated when deployed", async function () { | ||
const tx = await contract.Client.deploy( | ||
{ counter: INIT_VALUE }, | ||
{ | ||
networkPassphrase, | ||
rpcUrl, | ||
allowHttp: true, | ||
wasmHash: this.context.wasmHash, | ||
publicKey: this.context.keypair.publicKey(), | ||
...basicNodeSigner(this.context.keypair, networkPassphrase), | ||
}, | ||
); | ||
const { result: client } = await tx.signAndSend(); | ||
const t = await client.get(); | ||
expect(t.result, INIT_VALUE); | ||
}); | ||
|
||
it("fails with useful message if not given arguments", async function () { | ||
const tx = await contract.Client.deploy(null, { | ||
networkPassphrase, | ||
rpcUrl, | ||
allowHttp: true, | ||
wasmHash: this.context.wasmHash, | ||
publicKey: this.context.keypair.publicKey(), | ||
...basicNodeSigner(this.context.keypair, networkPassphrase), | ||
}); | ||
await expect(tx.signAndSend()) | ||
.to.be.rejectedWith( | ||
// placeholder error type | ||
contract.AssembledTransaction.Errors.SimulationFailed, | ||
) | ||
.then((error) => { | ||
// Further assertions on the error object | ||
expect(error).to.be.instanceOf( | ||
contract.AssembledTransaction.Errors.SimulationFailed, | ||
`error is not of type 'NeedMoreArgumentsError'; instead it is of type '${error?.constructor.name}'`, | ||
); | ||
|
||
if (error) { | ||
// Using regex to check the error message | ||
expect(error.message).to.match(/MismatchingParameterLen/); | ||
} | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.