Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/soroban uint32 #1691

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:

mac-intel:
name: Mac Intel
runs-on: macos-12
runs-on: macos-13
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand Down
19 changes: 15 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ jobs:
repolinter:
name: Repolinter
runs-on: solang-ubuntu-latest
# spdx runs on python 3.10 but not any later versions
container: ubuntu:22.04
steps:
- name: Install Python and npm
run: |
apt-get update
apt-get install -y python3 git npm
- name: Checkout sources
uses: actions/checkout@v4
- name: Run repolinter
run: npx repolinter --rulesetUrl https://raw.githubusercontent.com/hyperledger-labs/hyperledger-community-management-tools/master/repo_structure/repolint.json
- uses: enarx/spdx@master
with:
licenses: Apache-2.0 MIT
licenses: Apache-2.0

docs:
name: Docs
Expand Down Expand Up @@ -199,7 +205,7 @@ jobs:

mac-intel:
name: Mac Intel
runs-on: macos-12
runs-on: macos-13
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand All @@ -223,7 +229,7 @@ jobs:

mac-universal:
name: Mac Universal Binary
runs-on: macos-12
runs-on: macos-13
needs: [mac-arm, mac-intel]
steps:
- uses: actions/[email protected]
Expand Down Expand Up @@ -319,6 +325,8 @@ jobs:
with:
node-version: '16'
- uses: dtolnay/[email protected]
with:
target: wasm32-unknown-unknown
- uses: actions/[email protected]
with:
name: solang-linux-x86-64
Expand All @@ -329,14 +337,17 @@ jobs:
echo "$(pwd)/bin" >> $GITHUB_PATH

- name: Install Soroban
run: cargo install --locked soroban-cli --version 22.0.0
run: cargo install --locked stellar-cli --version 22.0.0
- name: Add cargo install location to PATH
run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- run: npm install
working-directory: ./integration/soroban
- name: Build Solang contracts
run: npm run build
working-directory: ./integration/soroban
- name: Build rust contracts
run: soroban contract build --profile release-with-logs
working-directory: ./integration/soroban/rust/contracts
- name: Setup Soroban enivronment
run: npm run setup
working-directory: ./integration/soroban
Expand Down
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ Cargo.lock
/target
**/*.rs.bk
*.ll
tests/.tmp*
tests/create_me/
/tests/.tmp*
/tests/create_me/
/test_snapshots/

.helix/
.vscode/

/test_snapshots

# Exclude macOS system files
.DS_Store
# Recursively ignore all .DS_Store files
**/.DS_Store
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.
1 change: 1 addition & 0 deletions incrementer.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"type":"constructor","inputs":[{"name":"initvalue","type":"uint32","internalType":"uint32"}],"stateMutability":"nonpayable"},{"name":"inc","type":"function","inputs":[{"name":"by","type":"uint32","internalType":"uint32"}],"outputs":[],"stateMutability":"nonpayable"},{"name":"add","type":"function","inputs":[{"name":"a","type":"uint32","internalType":"uint32"},{"name":"b","type":"uint32","internalType":"uint32"}],"outputs":[{"name":"","type":"uint32","internalType":"uint32"}],"stateMutability":"view"},{"name":"get","type":"function","inputs":[],"outputs":[{"name":"","type":"uint32","internalType":"uint32"}],"stateMutability":"view"}]
Binary file added incrementer.wasm
Binary file not shown.
Binary file added integration/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions integration/anchor/target/.rustc_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc_fingerprint":13881514899064403785,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/ahmadsameh/.rustup/toolchains/stable-x86_64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"sse4.1\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.83.0 (90b35a623 2024-11-26)\nbinary: rustc\ncommit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\ncommit-date: 2024-11-26\nhost: x86_64-apple-darwin\nrelease: 1.83.0\nLLVM version: 19.1.1\n","stderr":""}},"successes":{}}
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
Binary file added integration/subxt-tests/.DS_Store
Binary file not shown.
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