-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into expand_codeowners
- Loading branch information
Showing
41 changed files
with
949 additions
and
49 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
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
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,48 @@ | ||
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('Runtime Error', () => { | ||
let keypair; | ||
const server = new StellarSdk.SorobanRpc.Server( | ||
"https://soroban-testnet.stellar.org:443", | ||
); | ||
|
||
let contractAddr; | ||
let contract; | ||
before(async () => { | ||
|
||
console.log('Setting up runtime_error.sol 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', 'Error.txt'); | ||
// read contract address from file | ||
contractAddr = readFileSync(contractIdFile, 'utf8').trim().toString(); | ||
|
||
// load contract | ||
contract = new StellarSdk.Contract(contractAddr); | ||
|
||
// call decrement once. The second call however will result in a runtime error | ||
await call_contract_function("decrement", server, keypair, contract); | ||
}); | ||
|
||
it('get correct initial counter', async () => { | ||
|
||
// decrement the counter again, resulting in a runtime error | ||
let res = await call_contract_function("decrement", server, keypair, contract); | ||
|
||
expect(res).to.contain('runtime_error: math overflow in runtime_error.sol:6:9-19'); | ||
}); | ||
|
||
}); | ||
|
||
|
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,21 @@ | ||
contract storage_types { | ||
|
||
uint64 public temporary sesa = 1; | ||
uint64 public instance sesa1 = 1; | ||
uint64 public persistent sesa2 = 2; | ||
uint64 public sesa3 = 2; | ||
|
||
function inc() public { | ||
sesa++; | ||
sesa1++; | ||
sesa2++; | ||
sesa3++; | ||
} | ||
|
||
function dec() public { | ||
sesa--; | ||
sesa1--; | ||
sesa2--; | ||
sesa3--; | ||
} | ||
} |
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,84 @@ | ||
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'; // Helper to interact with the contract | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const dirname = path.dirname(__filename); | ||
|
||
describe('StorageTypes', () => { | ||
let keypair; | ||
const server = new StellarSdk.SorobanRpc.Server( | ||
"https://soroban-testnet.stellar.org:443", | ||
); | ||
|
||
let contractAddr; | ||
let contract; | ||
before(async () => { | ||
console.log('Setting up storage_types 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', 'storage_types.txt'); | ||
// Read contract address from file | ||
contractAddr = readFileSync(contractIdFile, 'utf8').trim().toString(); | ||
|
||
// Load contract | ||
contract = new StellarSdk.Contract(contractAddr); | ||
}); | ||
|
||
it('check initial values', async () => { | ||
// Check initial values of all storage variables | ||
let sesa = await call_contract_function("sesa", server, keypair, contract); | ||
expect(sesa.toString()).eq("1"); | ||
|
||
let sesa1 = await call_contract_function("sesa1", server, keypair, contract); | ||
expect(sesa1.toString()).eq("1"); | ||
|
||
let sesa2 = await call_contract_function("sesa2", server, keypair, contract); | ||
expect(sesa2.toString()).eq("2"); | ||
|
||
let sesa3 = await call_contract_function("sesa3", server, keypair, contract); | ||
expect(sesa3.toString()).eq("2"); | ||
}); | ||
|
||
it('increment values', async () => { | ||
// Increment all values by calling the inc function | ||
await call_contract_function("inc", server, keypair, contract); | ||
|
||
// Check the incremented values | ||
let sesa = await call_contract_function("sesa", server, keypair, contract); | ||
expect(sesa.toString()).eq("2"); | ||
|
||
let sesa1 = await call_contract_function("sesa1", server, keypair, contract); | ||
expect(sesa1.toString()).eq("2"); | ||
|
||
let sesa2 = await call_contract_function("sesa2", server, keypair, contract); | ||
expect(sesa2.toString()).eq("3"); | ||
|
||
let sesa3 = await call_contract_function("sesa3", server, keypair, contract); | ||
expect(sesa3.toString()).eq("3"); | ||
}); | ||
|
||
it('decrement values', async () => { | ||
// Decrement all values by calling the dec function | ||
await call_contract_function("dec", server, keypair, contract); | ||
|
||
// Check the decremented values | ||
let sesa = await call_contract_function("sesa", server, keypair, contract); | ||
expect(sesa.toString()).eq("1"); | ||
|
||
let sesa1 = await call_contract_function("sesa1", server, keypair, contract); | ||
expect(sesa1.toString()).eq("1"); | ||
|
||
let sesa2 = await call_contract_function("sesa2", server, keypair, contract); | ||
expect(sesa2.toString()).eq("2"); | ||
|
||
let sesa3 = await call_contract_function("sesa3", server, keypair, contract); | ||
expect(sesa3.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
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
Oops, something went wrong.