From 362c10797d79a125acf00a14490ed53f2433ecc4 Mon Sep 17 00:00:00 2001 From: Tarek Date: Sat, 30 Nov 2024 01:35:14 +0200 Subject: [PATCH] test(soroban): add no-argument constructor example Signed-off-by: Tarek --- integration/soroban/.gitignore | 1 - integration/soroban/constructor_no_args.sol | 11 +++++ integration/soroban/noargsconstructor.spec.js | 41 +++++++++++++++++++ integration/soroban/setup.js | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 integration/soroban/constructor_no_args.sol create mode 100644 integration/soroban/noargsconstructor.spec.js diff --git a/integration/soroban/.gitignore b/integration/soroban/.gitignore index ee0ea4517..270feccc9 100644 --- a/integration/soroban/.gitignore +++ b/integration/soroban/.gitignore @@ -1,4 +1,3 @@ -*.js *.so *.key *.json diff --git a/integration/soroban/constructor_no_args.sol b/integration/soroban/constructor_no_args.sol new file mode 100644 index 000000000..886fa466a --- /dev/null +++ b/integration/soroban/constructor_no_args.sol @@ -0,0 +1,11 @@ +contract noargsconstructor { + uint64 public count = 1; + + constructor() { + count += 1; + } + + function get() public view returns (uint64) { + return count; + } +} diff --git a/integration/soroban/noargsconstructor.spec.js b/integration/soroban/noargsconstructor.spec.js new file mode 100644 index 000000000..4cf637abc --- /dev/null +++ b/integration/soroban/noargsconstructor.spec.js @@ -0,0 +1,41 @@ +import * as StellarSdk from '@stellar/stellar-sdk'; +import { readFileSync } from 'fs'; +import { expect } from 'chai'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { call_contract_function } from './test_helpers.js'; + +const __filename = fileURLToPath(import.meta.url); +const dirname = path.dirname(__filename); + +describe('CounterWithNoArgsConstructor', () => { + let keypair; + const server = new StellarSdk.SorobanRpc.Server( + "https://soroban-testnet.stellar.org:443", + ); + + let contractAddr; + let contract; + before(async () => { + + console.log('Setting up counter with no-args constructor contract tests...'); + + // read secret from file + const secret = readFileSync('alice.txt', 'utf8').trim(); + keypair = StellarSdk.Keypair.fromSecret(secret); + + let contractIdFile = path.join(dirname, '.soroban', 'contract-ids', 'noargsconstructor.txt'); + // read contract address from file + contractAddr = readFileSync(contractIdFile, 'utf8').trim().toString(); + + // load contract + contract = new StellarSdk.Contract(contractAddr); + }); + + it('make sure the constructor of the contract was called', async () => { + // get the count + let count = await call_contract_function("get", server, keypair, contract); + expect(count.toString()).eq("2"); + }); + +}); diff --git a/integration/soroban/setup.js b/integration/soroban/setup.js index 7bdb32a8b..f8c789243 100644 --- a/integration/soroban/setup.js +++ b/integration/soroban/setup.js @@ -60,4 +60,5 @@ function add_testnet() { add_testnet(); generate_alice(); +// FIXME: This will need to be refactored to allow providing constructor arguments for a specific contract deploy_all();