Skip to content

Commit

Permalink
Use renamed custom types example contract (#1043)
Browse files Browse the repository at this point in the history
The custom-types contract was renamed in
stellar/soroban-examples#322. The e2e end tests
have been failing since then. This uses the renamed example contract to
fix the tests.

This also updates the pinned version of Stellar CLI. The latest CLI
fixes the bug that two tests were working around, so we no longer need
these tests.
  • Loading branch information
chadoh authored Sep 12, 2024
1 parent 3e081ba commit 581b32a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# paths = ["/path/to/override"] # path dependency overrides

[alias] # command aliases
install_soroban = "install --version 21.0.0-rc.1 --root ./target soroban-cli --debug"
install_soroban = "install --version 21.4.1 --root ./target soroban-cli --debug"
# b = "build --target wasm32-unknown-unknown --release"
# c = "check"
# t = "test"
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ target_dir="$dirname/test-contracts/target/wasm32-unknown-unknown/release"
contracts_dir="$dirname/test-contracts"
repo_url="https://github.com/stellar/soroban-examples.git"
wasm_files=(
"soroban_custom_types_contract.wasm"
"soroban_other_custom_types_contract.wasm"
"soroban_atomic_swap_contract.wasm"
"soroban_token_contract.wasm"
"soroban_increment_contract.wasm"
Expand Down Expand Up @@ -84,7 +84,7 @@ done
if [ "$all_exist" = false ] || [ "$current_hash" != "$stored_hash" ]; then
echo "WASM files are missing or contracts have been updated. Initializing and building contracts..."
# Initialize contracts
$soroban contract init "$dirname/test-contracts" --with-example increment custom_types atomic_swap token
$soroban contract init "$dirname/test-contracts" --with-example increment other_custom_types atomic_swap token

# Change directory to test-contracts and build the contracts
cd "$dirname/test-contracts" || { echo "Failed to change directory!"; exit 1; }
Expand Down
92 changes: 0 additions & 92 deletions test/e2e/src/test-swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,98 +99,6 @@ describe("Swap Contract Tests", function () {
});
});

it("modified & re-simulated transactions show updated data", async function () {
const tx = await this.context.swapContractAsRoot.swap({
a: this.context.alice.publicKey(),
b: this.context.bob.publicKey(),
token_a: this.context.tokenAId,
token_b: this.context.tokenBId,
amount_a: amountAToSwap,
min_a_for_b: amountAToSwap,
amount_b: amountBToSwap,
min_b_for_a: amountBToSwap,
});
await tx.signAuthEntries({
publicKey: this.context.alice.publicKey(),
...contract.basicNodeSigner(this.context.alice, networkPassphrase),
});
await tx.signAuthEntries({
publicKey: this.context.bob.publicKey(),
...contract.basicNodeSigner(this.context.bob, networkPassphrase),
});

const originalResourceFee = Number(
tx.simulationData.transactionData.resourceFee(),
);
const bumpedResourceFee = originalResourceFee + 10000;

tx.raw = TransactionBuilder.cloneFrom(tx.built, {
fee: tx.built.fee,
sorobanData: new SorobanDataBuilder(
tx.simulationData.transactionData.toXDR(),
)
.setResourceFee(
xdr.Int64.fromString(bumpedResourceFee.toString()).toBigInt(),
)
.build(),
});

await tx.simulate();

const newSimulatedResourceFee = Number(
tx.simulationData.transactionData.resourceFee(),
);

expect(originalResourceFee).to.not.equal(newSimulatedResourceFee);
expect(newSimulatedResourceFee).to.be.greaterThan(bumpedResourceFee);
});

it("modified & re-simulated transactions show updated data", async function () {
const tx = await this.context.swapContractAsRoot.swap({
a: this.context.alice.publicKey(),
b: this.context.bob.publicKey(),
token_a: this.context.tokenAId,
token_b: this.context.tokenBId,
amount_a: amountAToSwap,
min_a_for_b: amountAToSwap,
amount_b: amountBToSwap,
min_b_for_a: amountBToSwap,
});
await tx.signAuthEntries({
publicKey: this.context.alice.publicKey(),
...contract.basicNodeSigner(this.context.alice, networkPassphrase),
});
await tx.signAuthEntries({
publicKey: this.context.bob.publicKey(),
...contract.basicNodeSigner(this.context.bob, networkPassphrase),
});

const originalResourceFee = Number(
tx.simulationData.transactionData.resourceFee(),
);
const bumpedResourceFee = originalResourceFee + 10000;

tx.raw = TransactionBuilder.cloneFrom(tx.built, {
fee: tx.built.fee,
sorobanData: new SorobanDataBuilder(
tx.simulationData.transactionData.toXDR(),
)
.setResourceFee(
xdr.Int64.fromString(bumpedResourceFee.toString()).toBigInt(),
)
.build(),
});

await tx.simulate();

const newSimulatedResourceFee = Number(
tx.simulationData.transactionData.resourceFee(),
);

expect(originalResourceFee).to.not.equal(newSimulatedResourceFee);
expect(newSimulatedResourceFee).to.be.greaterThan(bumpedResourceFee);
});

it("alice swaps bob 10 A for 1 B", async function () {
const tx = await this.context.swapContractAsRoot.swap({
a: this.context.alice.publicKey(),
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const contracts = {
"contract",
"install",
"--wasm",
`${basePath}/soroban_custom_types_contract.wasm`,
`${basePath}/soroban_other_custom_types_contract.wasm`,
],
{ shell: true, encoding: "utf8" },
).stdout.trim(),
Expand Down

0 comments on commit 581b32a

Please sign in to comment.