-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(soroban): add no-argument constructor example
Signed-off-by: Tarek <tareknaser360@gmail.com>
- Loading branch information
1 parent
399b070
commit 362c107
Showing
4 changed files
with
53 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
*.js | ||
*.so | ||
*.key | ||
*.json | ||
|
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,11 @@ | ||
contract noargsconstructor { | ||
uint64 public count = 1; | ||
|
||
constructor() { | ||
count += 1; | ||
} | ||
|
||
function get() public view returns (uint64) { | ||
return count; | ||
} | ||
} |
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,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"); | ||
}); | ||
|
||
}); |
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