From 1c573cd40d38ce7c4882991fcee5227bb7b4a753 Mon Sep 17 00:00:00 2001 From: Blaine Heffron Date: Wed, 19 Jun 2024 10:09:19 -0400 Subject: [PATCH] script to use init plus some initial changes to tests --- test/e2e/.gitignore | 1 + test/e2e/initialize.sh | 34 +++++++++++++++++ .../src/test-contract-client-constructor.js | 4 +- test/e2e/src/test-custom-types.js | 8 +--- test/e2e/src/util.js | 37 ++++++++++++++----- 5 files changed, 67 insertions(+), 17 deletions(-) diff --git a/test/e2e/.gitignore b/test/e2e/.gitignore index d8dea8c98..b2c0d97d4 100644 --- a/test/e2e/.gitignore +++ b/test/e2e/.gitignore @@ -4,3 +4,4 @@ yarn.lock contract-*.txt .soroban wasms/specs/*.json +test-contracts \ No newline at end of file diff --git a/test/e2e/initialize.sh b/test/e2e/initialize.sh index 740a90ac7..de87aa038 100755 --- a/test/e2e/initialize.sh +++ b/test/e2e/initialize.sh @@ -42,3 +42,37 @@ if [[ "$NETWORK_STATUS" != "healthy" ]]; then fi $soroban keys generate $SOROBAN_ACCOUNT + +# retrieve the contracts using soroban contract init then build them if they dont already exist +# Define directory and WASM file paths +target_dir="$dirname/test-contracts/target/wasm32-unknown-unknown/release" +wasm_files=( + "soroban_custom_types_contract.wasm" + "soroban_atomic_swap_contract.wasm" + "soroban_token_contract.wasm" + "soroban_increment_contract.wasm" + "hello_world.wasm" +) + +# Check if all WASM files exist +all_exist=true +for wasm_file in "${wasm_files[@]}"; do + if [ ! -f "$target_dir/$wasm_file" ]; then + all_exist=false + break + fi +done + +# If any WASM file is missing, initialize and build the contracts +if [ "$all_exist" = false ]; then + echo "One or more WASM files are missing. Initializing and building contracts..." + + # Initialize contracts + $soroban contract init "$dirname/test-contracts" --with-example increment 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; } + $soroban contract build +else + echo "All WASM files are present." +fi diff --git a/test/e2e/src/test-contract-client-constructor.js b/test/e2e/src/test-contract-client-constructor.js index da40738a7..045020fa5 100644 --- a/test/e2e/src/test-contract-client-constructor.js +++ b/test/e2e/src/test-contract-client-constructor.js @@ -93,14 +93,14 @@ describe('Client', function() { before(async function() { const { client, keypair, contractId } = - await clientFromConstructor("customTypes"); + await clientFromConstructor("helloWorld"); const publicKey = keypair.publicKey(); const addr = Address.fromString(publicKey); this.context = { client, publicKey, addr, contractId, keypair }; }); it("can be constructed with `new Client`", async function() { - const { result } = await this.context.client.hello({ hello: "tests" }); + const { result } = await this.context.client.hello({ to: "tests" }); expect(result).to.equal("tests"); }); diff --git a/test/e2e/src/test-custom-types.js b/test/e2e/src/test-custom-types.js index 778a4eeb0..f032df00b 100644 --- a/test/e2e/src/test-custom-types.js +++ b/test/e2e/src/test-custom-types.js @@ -11,16 +11,12 @@ describe("Custom Types Tests", function() { this.context = { client, publicKey, addr, contractId, keypair }; }); - it("hello", async function() { - expect((await this.context.client.hello({ hello: "tests" })).result).to.equal("tests"); - }); - it("view method with empty keypair", async function() { - const { client: client2 } = await clientFor("customTypes", { + const { client: client2 } = await clientFor("helloWorld", { keypair: undefined, contractId: this.context.contractId, }); - expect((await client2.hello({ hello: "anonymous" })).result).to.equal("anonymous"); + expect((await client2.hello({ to: "anonymous" })).result).to.equal("anonymous"); }); it("woid", async function() { diff --git a/test/e2e/src/util.js b/test/e2e/src/util.js index 6d760c976..43d94ec56 100644 --- a/test/e2e/src/util.js +++ b/test/e2e/src/util.js @@ -1,6 +1,7 @@ const { spawnSync } = require("node:child_process"); const { contract, Keypair } = require("../../.."); +const basePath = `${__dirname}/../test-contracts/target/wasm32-unknown-unknown/release`; const contracts = { customTypes: { hash: spawnSync( @@ -9,11 +10,11 @@ const contracts = { "contract", "install", "--wasm", - `${__dirname}/../wasms/test_custom_types.wasm`, + `${basePath}/soroban_custom_types_contract.wasm`, ], { shell: true, encoding: "utf8" }, ).stdout.trim(), - path: `${__dirname}/../wasms/test_custom_types.wasm`, + path: `${basePath}/soroban_custom_types_contract.wasm`, }, helloWorld: { hash: spawnSync( @@ -22,19 +23,37 @@ const contracts = { "contract", "install", "--wasm", - `${__dirname}/../wasms/test_hello_world.wasm`, + `${basePath}/hello_world.wasm`, ], { shell: true, encoding: "utf8" }, ).stdout.trim(), - path: `${__dirname}/../wasms/test_hello_world.wasm`, + path: `${basePath}/hello_world.wasm`, + }, + increment: { + hash: spawnSync( + "./target/bin/soroban", + [ + "contract", + "install", + "--wasm", + `${basePath}/soroban_increment_contract.wasm`, + ], + { shell: true, encoding: "utf8" }, + ).stdout.trim(), + path: `${basePath}/soroban_increment_contract.wasm`, }, swap: { hash: spawnSync( "./target/bin/soroban", - ["contract", "install", "--wasm", `${__dirname}/../wasms/test_swap.wasm`], + [ + "contract", + "install", + "--wasm", + `${basePath}/soroban_atomic_swap_contract.wasm`, + ], { shell: true, encoding: "utf8" }, ).stdout.trim(), - path: `${__dirname}/../wasms/test_swap.wasm`, + path: `${basePath}/soroban_atomic_swap_contract.wasm`, }, token: { hash: spawnSync( @@ -43,11 +62,11 @@ const contracts = { "contract", "install", "--wasm", - `${__dirname}/../wasms/test_token.wasm`, + `${basePath}/soroban_token_contract.wasm`, ], { shell: true, encoding: "utf8" }, ).stdout.trim(), - path: `${__dirname}/../wasms/test_token.wasm`, + path: `${basePath}/soroban_token_contract.wasm`, }, }; module.exports.contracts = contracts; @@ -65,7 +84,7 @@ module.exports.friendbotUrl = friendbotUrl; async function generateFundedKeypair() { const keypair = Keypair.random(); - await fetch(`${friendbotUrl}/friendbot?addr=${keypair.publicKey()}`); + await fetch(`${friendbotUrl}/?addr=${keypair.publicKey()}`); return keypair; } module.exports.generateFundedKeypair = generateFundedKeypair;