Skip to content

Commit

Permalink
test(soroban): add no-argument constructor example
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <tareknaser360@gmail.com>
  • Loading branch information
tareknaser committed Nov 29, 2024
1 parent 399b070 commit 362c107
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
1 change: 0 additions & 1 deletion integration/soroban/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.js
*.so
*.key
*.json
Expand Down
11 changes: 11 additions & 0 deletions integration/soroban/constructor_no_args.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contract noargsconstructor {
uint64 public count = 1;

constructor() {
count += 1;
}

function get() public view returns (uint64) {
return count;
}
}
41 changes: 41 additions & 0 deletions integration/soroban/noargsconstructor.spec.js
Original file line number Diff line number Diff line change
@@ -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");
});

});
1 change: 1 addition & 0 deletions integration/soroban/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 362c107

Please sign in to comment.