Skip to content

Commit

Permalink
Split out soroban-rpc test contract and remove rlib to reduce size un…
Browse files Browse the repository at this point in the history
…der 1KB
  • Loading branch information
2opremio committed Aug 28, 2023
1 parent 30068d0 commit 2ffde3f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 34 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#![no_std]
use soroban_sdk::{
contract, contractimpl, log, symbol_short, vec, Address, Env, String, Symbol, Vec,
};

const COUNTER: Symbol = symbol_short!("COUNTER");
use soroban_sdk::{contract, contractimpl, log, symbol_short, vec, Env, String, Symbol, Vec};

#[contract]
pub struct Contract;
Expand All @@ -22,25 +18,6 @@ impl Contract {
vec![&env, !boolean]
}

pub fn auth(env: Env, addr: Address, world: Symbol) -> Address {
addr.require_auth();
// Emit test event
env.events().publish(("auth",), world);

addr
}

pub fn inc(env: Env) {
let mut count: u32 = env.storage().persistent().get(&COUNTER).unwrap_or(0); // Panic if the value of COUNTER is not u32.
log!(&env, "count: {}", count);

// Increment the count.
count += 1;

// Save the count.
env.storage().persistent().set(&COUNTER, &count);
}

#[allow(unused_variables)]
pub fn multi_word_cmd(env: Env, contract_owner: String) {}
/// Logs a string with `hello ` in front.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "test_soroban_rpc"
version = "0.9.4"
authors = ["Stellar Development Foundation <info@stellar.org>"]
license = "Apache-2.0"
edition = "2021"
publish = false
rust-version = "1.70"

[lib]
crate-type = ["cdylib"]
doctest = false

[dependencies]
soroban-sdk = { workspace = true }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![no_std]
use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env, Symbol};

const COUNTER: Symbol = symbol_short!("COUNTER");

#[contract]
pub struct Contract;

#[contractimpl]
impl Contract {
pub fn auth(env: Env, addr: Address, world: Symbol) -> Address {
addr.require_auth();
// Emit test event
env.events().publish(("auth",), world);

addr
}

pub fn inc(env: Env) {
let mut count: u32 = env.storage().persistent().get(&COUNTER).unwrap_or(0); // Panic if the value of COUNTER is not u32.

// Increment the count.
count += 1;
// Save the count.
env.storage().persistent().set(&COUNTER, &count);
}
}
20 changes: 10 additions & 10 deletions cmd/soroban-rpc/internal/test/simulate_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ var (
}
)

func getHelloWorldContract(t *testing.T) []byte {
func getSorobanRPCTestContract(t *testing.T) []byte {
_, filename, _, _ := runtime.Caller(0)
testDirName := path.Dir(filename)
contractFile := path.Join(testDirName, "../../../../target/wasm32-unknown-unknown/test-wasms/test_hello_world.wasm")
contractFile := path.Join(testDirName, "../../../../target/wasm32-unknown-unknown/test-wasms/test_soroban_rpc.wasm")
ret, err := os.ReadFile(contractFile)
if err != nil {
t.Fatalf("unable to read test_hello_world.wasm (%v) please run `make build-test-wasms` at the project root directory", err)
t.Fatalf("unable to read test_soroban_rpc.wasm (%v) please run `make build-test-wasms` at the project root directory", err)
}
return ret
}
Expand Down Expand Up @@ -313,13 +313,13 @@ func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) {
address := sourceAccount.Address()
account := txnbuild.NewSimpleAccount(address, 0)

helloWorldContract := getHelloWorldContract(t)
sorobanRPCTestContract := getSorobanRPCTestContract(t)

params := preflightTransactionParams(t, client, txnbuild.TransactionParams{
SourceAccount: &account,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
createInstallContractCodeOperation(account.AccountID, helloWorldContract),
createInstallContractCodeOperation(account.AccountID, sorobanRPCTestContract),
},
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{
Expand All @@ -335,7 +335,7 @@ func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) {
SourceAccount: &account,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
createCreateContractOperation(t, address, helloWorldContract, StandaloneNetworkPassphrase),
createCreateContractOperation(t, address, sorobanRPCTestContract, StandaloneNetworkPassphrase),
},
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{
Expand Down Expand Up @@ -433,7 +433,7 @@ func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) {
assert.Equal(t, xdr.ScValTypeScvLedgerKeyContractInstance, ro1.ContractData.Key.Type)
ro2 := obtainedFootprint.ReadOnly[2]
assert.Equal(t, xdr.LedgerEntryTypeContractCode, ro2.Type)
contractHash := sha256.Sum256(helloWorldContract)
contractHash := sha256.Sum256(sorobanRPCTestContract)
assert.Equal(t, xdr.Hash(contractHash), ro2.ContractCode.Hash)
assert.NoError(t, err)

Expand Down Expand Up @@ -621,13 +621,13 @@ func TestSimulateTransactionBumpAndRestoreFootprint(t *testing.T) {
address := sourceAccount.Address()
account := txnbuild.NewSimpleAccount(address, 0)

helloWorldContract := getHelloWorldContract(t)
sorobanRPCTestContract := getSorobanRPCTestContract(t)

params := preflightTransactionParams(t, client, txnbuild.TransactionParams{
SourceAccount: &account,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
createInstallContractCodeOperation(account.AccountID, helloWorldContract),
createInstallContractCodeOperation(account.AccountID, sorobanRPCTestContract),
},
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{
Expand All @@ -642,7 +642,7 @@ func TestSimulateTransactionBumpAndRestoreFootprint(t *testing.T) {
SourceAccount: &account,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
createCreateContractOperation(t, address, helloWorldContract, StandaloneNetworkPassphrase),
createCreateContractOperation(t, address, sorobanRPCTestContract, StandaloneNetworkPassphrase),
},
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{
Expand Down

0 comments on commit 2ffde3f

Please sign in to comment.