Skip to content

Commit

Permalink
added unit test and integration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadsamehh committed Feb 4, 2025
1 parent ff8f788 commit 46d08d1
Show file tree
Hide file tree
Showing 1,244 changed files with 485,723 additions and 37 deletions.
Binary file modified .DS_Store
Binary file not shown.
51 changes: 41 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,42 +1,64 @@
[package]
name = "solang"
version = "0.3.3"
authors = ["Sean Young <[email protected]>", "Lucas Steuernagel <[email protected]>", "Cyrill Leutwiler <[email protected]>"]
authors = [
"Sean Young <[email protected]>",
"Lucas Steuernagel <[email protected]>",
"Cyrill Leutwiler <[email protected]>",
]
repository = "https://github.com/hyperledger-solang/solang"
documentation = "https://solang.readthedocs.io/"
license = "Apache-2.0"
build = "build.rs"
description = "Solang Solidity Compiler"
keywords = [ "solidity", "compiler", "solana", "polkadot", "substrate" ]
keywords = ["solidity", "compiler", "solana", "polkadot", "substrate"]
rust-version = "1.81.0"
edition = "2021"
exclude = [ "/.*", "/docs", "/examples", "/solana-library", "/tests", "/integration", "/vscode", "/testdata" ]
exclude = [
"/.*",
"/docs",
"/examples",
"/solana-library",
"/tests",
"/integration",
"/vscode",
"/testdata",
]

[build-dependencies]
cc = "1.0"

[dependencies]
llvm-sys = "160.0"
regex = "1"
rand = "0.8"
num-bigint = { version = "0.4", features = ["rand"]}
num-bigint = { version = "0.4", features = ["rand"] }
num-traits = "0.2"
num-integer = "0.1"
clap = {version = "4.5", features = ["derive"]}
clap = { version = "4.5", features = ["derive"] }
clap_complete = "4.5"
hex = "0.4"
tiny-keccak = { version = "2.0", features = ["keccak"] }
serde_json = "1.0"
serde = "1.0"
serde_derive = { version = "1.0" }
inkwell = { version = "0.4.0", features = ["target-webassembly", "no-libffi-linking", "llvm16-0"], optional = true }
inkwell = { version = "0.4.0", features = [
"target-webassembly",
"no-libffi-linking",
"llvm16-0",
], optional = true }
blake2-rfc = "0.2.18"
handlebars = "5.1"
contract-metadata = "4.0.2"
semver = { version = "1.0", features = ["serde"] }
tempfile = "3.10"
libc = { version = "0.2", optional = true }
tower-lsp = { version = "0.20", optional = true }
tokio = { version = "1.27", features = ["rt", "io-std", "macros"], optional = true }
tokio = { version = "1.27", features = [
"rt",
"io-std",
"macros",
], optional = true }
base58 = "0.2.0"
sha2 = "0.10"
ripemd = "0.1"
Expand Down Expand Up @@ -71,7 +93,10 @@ forge-fmt = { path = "fmt", optional = true }
# We don't use ethers-core directly, but need the correct version for the
# build to work.
ethers-core = { version = "2.0.10", optional = true }
soroban-sdk = { version = "22.0.0-rc.3.2", features = ["testutils"], optional = true }
soroban-sdk = { version = "22.0.0-rc.3.2", features = [
"testutils",
], optional = true }


[dev-dependencies]
num-derive = "0.4"
Expand All @@ -91,7 +116,7 @@ rayon = "1"
walkdir = "2.4"
ink_primitives = "5.0.0"
wasm_host_attr = { path = "tests/wasm_host_attr" }
num-bigint = { version = "0.4", features = ["rand", "serde"]}
num-bigint = { version = "0.4", features = ["rand", "serde"] }

[package.metadata.docs.rs]
no-default-features = true
Expand All @@ -104,7 +129,13 @@ soroban = ["soroban-sdk"]
default = ["llvm", "wasm_opt", "language_server", "soroban"]
llvm = ["inkwell", "libc"]
wasm_opt = ["llvm", "wasm-opt", "contract-build"]
language_server = ["tower-lsp", "forge-fmt", "ethers-core", "tokio", "rust-lapper"]
language_server = [
"tower-lsp",
"forge-fmt",
"ethers-core",
"tokio",
"rust-lapper",
]

[workspace]
members = ["solang-parser", "fmt", "tests/wasm_host_attr"]
1 change: 1 addition & 0 deletions counter.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"count","type":"function","inputs":[],"outputs":[{"name":"count","type":"uint64","internalType":"uint64"}],"stateMutability":"view"},{"name":"increment","type":"function","inputs":[],"outputs":[{"name":"","type":"uint64","internalType":"uint64"}],"stateMutability":"nonpayable"},{"name":"decrement","type":"function","inputs":[],"outputs":[{"name":"","type":"uint64","internalType":"uint64"}],"stateMutability":"nonpayable"},{"name":"additionu32","type":"function","inputs":[{"name":"a","type":"uint32","internalType":"uint32"},{"name":"b","type":"uint32","internalType":"uint32"}],"outputs":[{"name":"","type":"uint32","internalType":"uint32"}],"stateMutability":"nonpayable"}]
Binary file added counter.wasm
Binary file not shown.
Binary file added integration/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions integration/soroban/Error.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"decrement","type":"function","inputs":[],"outputs":[{"name":"","type":"uint64","internalType":"uint64"}],"stateMutability":"nonpayable"}]
Binary file added integration/soroban/Error.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions integration/soroban/counter.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"count","type":"function","inputs":[],"outputs":[{"name":"count","type":"uint64","internalType":"uint64"}],"stateMutability":"view"},{"name":"increment","type":"function","inputs":[],"outputs":[{"name":"","type":"uint64","internalType":"uint64"}],"stateMutability":"nonpayable"},{"name":"decrement","type":"function","inputs":[],"outputs":[{"name":"","type":"uint64","internalType":"uint64"}],"stateMutability":"nonpayable"},{"name":"additionu32","type":"function","inputs":[{"name":"a","type":"uint32","internalType":"uint32"},{"name":"b","type":"uint32","internalType":"uint32"}],"outputs":[{"name":"","type":"uint32","internalType":"uint32"}],"stateMutability":"nonpayable"}]
5 changes: 5 additions & 0 deletions integration/soroban/counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ contract counter {
count -= 1;
return count;
}

function additionu32 (uint32 a , uint32 b) public returns (uint32){
return a+b;
}

}
19 changes: 17 additions & 2 deletions integration/soroban/counter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from 'chai';
import path from 'path';
import { fileURLToPath } from 'url';
import { call_contract_function } from './test_helpers.js';
import exp from 'constants';

const __filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(__filename);
Expand All @@ -13,17 +14,18 @@ describe('Counter', () => {
const server = new StellarSdk.SorobanRpc.Server(
"https://soroban-testnet.stellar.org:443",
);

console.log('server', server);
let contractAddr;
let contract;
before(async () => {

console.log('Setting up counter contract tests...');

// read secret from file
const secret = readFileSync('alice.txt', 'utf8').trim();
const secret = readFileSync('/Users/ahmadsameh/Desktop/Work/salahswork/Soroban/solang/integration/soroban/alice.txt', 'utf8').trim();
keypair = StellarSdk.Keypair.fromSecret(secret);


let contractIdFile = path.join(dirname, '.soroban', 'contract-ids', 'counter.txt');
// read contract address from file
contractAddr = readFileSync(contractIdFile, 'utf8').trim().toString();
Expand All @@ -35,6 +37,7 @@ describe('Counter', () => {
it('get correct initial counter', async () => {
// get the count
let count = await call_contract_function("count", server, keypair, contract);
console.log(`initial counter is: ${count}`);
expect(count.toString()).eq("10");
});

Expand All @@ -46,6 +49,18 @@ describe('Counter', () => {
let count = await call_contract_function("count", server, keypair, contract);
expect(count.toString()).eq("11");
});

it('adding two numbers', async () => {
// add two numbers
let args = [
StellarSdk.xdr.ScVal.scvU32(30),
StellarSdk.xdr.ScVal.scvU32(40)
];

let result = await call_contract_function("additionu32", server, keypair, contract, ...args); // let returnValue = result.returnValue().value().toString();
console.log(`additionu32 output is: ${result}`);
expect(result.toString()).eq("70");
});
});


Binary file added integration/soroban/counter.wasm
Binary file not shown.
42 changes: 21 additions & 21 deletions integration/soroban/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"type": "module",
"dependencies": {
"@stellar/stellar-sdk": "^12.0.1",
"chai": "^5.1.1",
"dotenv": "^16.4.5",
"mocha": "^10.4.0"
},
"scripts": {
"build": "solang compile *.sol --target soroban && solang compile storage_types.sol --target soroban --release",
"setup": "node setup.js",
"test": "mocha *.spec.js --timeout 100000"
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"@types/mocha": "^10.0.6",
"eslint": "^9.4.0",
"expect": "^29.7.0",
"globals": "^15.4.0",
"typescript": "^5.4.5"
}
"type": "module",
"dependencies": {
"@stellar/stellar-sdk": "^12.0.1",
"chai": "^5.1.1",
"dotenv": "^16.4.7",
"mocha": "^10.4.0"
},
"scripts": {
"build": "solang compile *.sol --target soroban && solang compile counter.sol --target soroban --release",
"setup": "node setup.js",
"test": "mocha *.spec.js --timeout 100000",
"testcounter": "mocha counter.spec.js --timeout 100000"
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"@types/mocha": "^10.0.6",
"eslint": "^9.4.0",
"expect": "^29.7.0",
"globals": "^15.4.0",
"typescript": "^5.4.5"
}
}
1 change: 1 addition & 0 deletions integration/soroban/storage_types.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"sesa","type":"function","inputs":[],"outputs":[{"name":"sesa","type":"uint64","internalType":"uint64"}],"stateMutability":"view"},{"name":"sesa1","type":"function","inputs":[],"outputs":[{"name":"sesa1","type":"uint64","internalType":"uint64"}],"stateMutability":"view"},{"name":"sesa2","type":"function","inputs":[],"outputs":[{"name":"sesa2","type":"uint64","internalType":"uint64"}],"stateMutability":"view"},{"name":"sesa3","type":"function","inputs":[],"outputs":[{"name":"sesa3","type":"uint64","internalType":"uint64"}],"stateMutability":"view"},{"name":"inc","type":"function","inputs":[],"outputs":[],"stateMutability":"nonpayable"},{"name":"dec","type":"function","inputs":[],"outputs":[],"stateMutability":"nonpayable"}]
Binary file added integration/soroban/storage_types.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/soroban/test_helpers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as StellarSdk from '@stellar/stellar-sdk';

export async function call_contract_function(method, server, keypair, contract) {
export async function call_contract_function(method, server, keypair, contract, ...params) {
let res = null;

try {
let builtTransaction = new StellarSdk.TransactionBuilder(await server.getAccount(keypair.publicKey()), {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET,
}).addOperation(contract.call(method)).setTimeout(30).build();
}).addOperation(contract.call(method, ...params)).setTimeout(30).build();

let preparedTransaction = await server.prepareTransaction(builtTransaction);

Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/node-gyp-build

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/node-gyp-build-optional

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/node-gyp-build-test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/sha.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 46d08d1

Please sign in to comment.