Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
remove breaking changes on "connect to signer"
Browse files Browse the repository at this point in the history
  • Loading branch information
aemil145 committed Apr 29, 2022
1 parent 2886ace commit 2d41c86
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,12 @@ You can get an instance of a contract (e.g. with `getContractFactory()`). Here i
### Exposed functions of a contract instance
| Function | Descripton | Sample usage |
| --- | --- | --- |
| async deploy(initMsg, label = null) | Deploys the conttract with the given `initMsg`. Optionally you can deploy with a label other than the default one. | const deploy = await contract.deploy(MSG_INIT) |
| async execute(msg, signer = null) | Executes a transaction within the contract with the given message. Optionally you can execute with a signer other than the contract default one. | const result = await contract.execute(MSG_INCREMENT) |
| async query(queryMsg, signer = null) | Executes a query within the contract with the given message. Optionally you can make a query with a signer other than the contract default one. | const count = await contract.query(QUERY_GET_COUNT) |
| connectSigner(signer) | Sets the given signer as the contract default | contract.connectSigner(bob) |
| getAddress() | Returns the address of a deloyed contract or `null` if the contract is not deployed. | const address = contract.getAddress() |
| Function | Descripton | Sample usage |
| --- | --- | --- |
| async deploy(initMsg, signer = undefined, label = undefined, funds) | Deploys the conttract with the given `initMsg`. Optionally you can deploy with a signer and label other than the default ones. The deployer will become the default signer for the contract. You can also pass funds to automatically add selected amount of cudos to a contract on deployment. | const deploy = await contract.deploy(MSG_INIT, undefined, 'myLabel') |
| async execute(msg, signer = undefined) | Executes a transaction within the contract with the given message. Optionally you can execute with a signer other than the deployer. | const result = await contract.execute(MSG_INCREMENT) |
| async query(queryMsg, signer = undefined) | Executes a query within the contract with the given message. Optionally you can make a query with a signer other than the deployer. | const count = await contract.query(QUERY_GET_COUNT) |
| getAddress() | Returns the address of a deloyed contract or `null` if the contract is not deployed. | const address = contract.getAddress() |
You can run your scripts on a different node. More information [here](#network). You can set a custom address prefix under `addressPrefix` in `blast.config.js`. Default is `cudos`.
Expand Down
4 changes: 2 additions & 2 deletions packages/blast-tests/e2e-tests/tests/compile-run.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ fi

echo -n 'deploy and fund contract...'

perl -pi -e $'s|defaultNetwork: \'https://an-inhospitable-node.cudos.org:26657\'|defaultNetwork: \'\'|' blast.config.js
# tweak the deploy script to get cudos and pass it to the deploy function
perl -i -pe $'if($. == 1) {s||const { coin } = require(\'\@cosmjs/stargate\');\n\n|}' ./scripts/deploy.js
perl -i -pe $'if($. == 4) {s|| const fund = [coin(321, \'acudos\')];\n|}' ./scripts/deploy.js
perl -pi -e 's|\(MSG_INIT\)|(MSG_INIT, fund)|' ./scripts/deploy.js
perl -pi -e 's|deploy\(MSG_INIT|deploy(MSG_INIT, undefined, undefined, fund|' ./scripts/deploy.js

deployed_contract=`blast run ./scripts/deploy.js`
if [[ $deployed_contract =~ 'cudos' ]]; then
Expand Down
7 changes: 2 additions & 5 deletions packages/blast-utilities/contract-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports.CudosContract = class CudosContract {
}
}

async deploy(initMsg, funds, label = this.#contractLabel) {
async deploy(initMsg, signer = this.#signer, label = this.#contractLabel, funds) {
this.#signer = signer
const uploadTx = await this.#uploadContract()
const initTx = await this.#initContract(uploadTx.codeId, initMsg, label, funds)
this.#contractAddress = initTx.contractAddress
Expand All @@ -46,10 +47,6 @@ module.exports.CudosContract = class CudosContract {
return await signer.queryContractSmart(this.#contractAddress, queryMsg)
}

connectSigner(signer) {
this.#signer = signer
}

getAddress() {
return this.#contractAddress
}
Expand Down
4 changes: 2 additions & 2 deletions template/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
async function main () {
const [alice, bob] = await getSigners()

const contract = await getContractFactory('alpha', bob)
const contract = await getContractFactory('alpha')

const MSG_INIT = { count: 13 }
const deploy = await contract.deploy(MSG_INIT)
const deploy = await contract.deploy(MSG_INIT, bob)
const contractAddress = deploy.initTx.contractAddress
console.log(`Contract deployed at: ${contractAddress}`)
}
Expand Down
4 changes: 2 additions & 2 deletions template/scripts/interact.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
async function main() {
const [alice, bob] = await getSigners()
const contract = await getContractFromAddress('cudos1uul3yzm2lgskp3dxpj0zg558hppxk6pt8t00qe')
const contract = await getContractFromAddress('cudos1uul3yzm2lgskp3dxpj0zg558hppxk6pt8t00qe', bob)

const QUERY_GET_COUNT = { get_count: {} }
let count = await contract.query(QUERY_GET_COUNT)
console.log('Initial count: ' + count.count)

const MSG_INCREMENT = { increment: {} }
const result = await contract.execute(MSG_INCREMENT, bob)
const result = await contract.execute(MSG_INCREMENT)
console.log(result)

count = await contract.query(QUERY_GET_COUNT, alice)
Expand Down
5 changes: 3 additions & 2 deletions template/tests/alpha.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ describe('alpha contract', () => {
let alice, bob, contract

beforeAll(async () => {
// default timeout is 15000
jest.setTimeout(20000);
[alice, bob] = await getSigners()
contract = await getContractFactory('alpha', bob)
await contract.deploy(MSG_INIT)
contract = await getContractFactory('alpha')
await contract.deploy(MSG_INIT, bob)
})

test('increment count', async () => {
Expand Down

0 comments on commit 2d41c86

Please sign in to comment.