From 4b4bbf5053e2d786aed4e0ea51b3c97e19a6c717 Mon Sep 17 00:00:00 2001 From: Blaine Heffron Date: Thu, 20 Jun 2024 15:12:46 -0400 Subject: [PATCH] finish getting tests working --- .../src/test-contract-client-constructor.js | 2 +- test/e2e/src/test-custom-types.js | 26 ++++++++++++-- test/e2e/src/test-hello-world.js | 34 ------------------- test/e2e/src/test-methods-as-args.js | 2 +- test/e2e/src/util.js | 2 +- 5 files changed, 26 insertions(+), 40 deletions(-) delete mode 100644 test/e2e/src/test-hello-world.js diff --git a/test/e2e/src/test-contract-client-constructor.js b/test/e2e/src/test-contract-client-constructor.js index 045020fa5..4eebf5bca 100644 --- a/test/e2e/src/test-contract-client-constructor.js +++ b/test/e2e/src/test-contract-client-constructor.js @@ -101,7 +101,7 @@ describe('Client', function() { it("can be constructed with `new Client`", async function() { const { result } = await this.context.client.hello({ to: "tests" }); - expect(result).to.equal("tests"); + expect(result).to.deep.equal(["Hello", "tests"]); }); it("can be constructed with `from`", async function() { diff --git a/test/e2e/src/test-custom-types.js b/test/e2e/src/test-custom-types.js index f032df00b..4639d9667 100644 --- a/test/e2e/src/test-custom-types.js +++ b/test/e2e/src/test-custom-types.js @@ -12,17 +12,37 @@ describe("Custom Types Tests", function() { }); it("view method with empty keypair", async function() { - const { client: client2 } = await clientFor("helloWorld", { + const { client: client2 } = await clientFor("customTypes", { keypair: undefined, - contractId: this.context.contractId, + contractId: this.context.contractId }); - expect((await client2.hello({ to: "anonymous" })).result).to.equal("anonymous"); + expect((await client2.i32_({ i32_: 1 })).result).to.equal(1); + }); + + it("should increment the counter correctly", async function() { + const { result: startingBalance } = await this.context.client.get_count(); + const inc = await this.context.client.inc(); + const incrementResponse = await inc.signAndSend(); + expect(incrementResponse.result).to.equal(startingBalance + 1); + expect(startingBalance).to.equal(0); // Assuming the counter starts at 0 + const { result: newBalance } = await this.context.client.get_count(); + expect(newBalance).to.equal(startingBalance + 1); + }); + + it("should accept only options object for methods with no arguments", async function() { + const inc = await this.context.client.inc({ simulate: false }); + expect(inc.simulation).to.be.undefined; }); it("woid", async function() { expect((await this.context.client.woid()).result).to.be.null; }); + it("should authenticate the user correctly", async function() { + const { result } = await this.context.client.auth({ addr: this.context.publicKey, world: "lol" }); + expect(result).to.equal(this.context.publicKey); + }); + it("u32_fail_on_even", async function() { let response = await this.context.client.u32_fail_on_even({ u32_: 1 }); expect(response.result).to.deep.equal(new contract.Ok(1)); diff --git a/test/e2e/src/test-hello-world.js b/test/e2e/src/test-hello-world.js deleted file mode 100644 index 50b50f4f7..000000000 --- a/test/e2e/src/test-hello-world.js +++ /dev/null @@ -1,34 +0,0 @@ -const { expect } = require("chai"); -const { clientFor } = require("./util"); - -describe("helloWorld client", function() { - it("should return properly formed hello response", async function() { - const { client } = await clientFor("helloWorld"); - const response = await client.hello({ world: "tests" }); - expect(response.result).to.deep.equal(["Hello", "tests"]); - }); - - it("should authenticate the user correctly", async function() { - const { client, keypair } = await clientFor("helloWorld"); - const publicKey = keypair.publicKey(); - const { result } = await client.auth({ addr: publicKey, world: "lol" }); - expect(result).to.equal(publicKey); - }); - - it("should increment the counter correctly", async function() { - const { client } = await clientFor("helloWorld"); - const { result: startingBalance } = await client.get_count(); - const inc = await client.inc(); - const incrementResponse = await inc.signAndSend(); - expect(incrementResponse.result).to.equal(startingBalance + 1); - expect(startingBalance).to.equal(0); // Assuming the counter starts at 0 - const { result: newBalance } = await client.get_count(); - expect(newBalance).to.equal(startingBalance + 1); - }); - - it("should accept only options object for methods with no arguments", async function() { - const { client } = await clientFor("helloWorld"); - const inc = await client.inc({ simulate: false }); - expect(inc.simulation).to.be.undefined; - }); -}); diff --git a/test/e2e/src/test-methods-as-args.js b/test/e2e/src/test-methods-as-args.js index 1f4b5b5ef..906c80918 100644 --- a/test/e2e/src/test-methods-as-args.js +++ b/test/e2e/src/test-methods-as-args.js @@ -9,7 +9,7 @@ function callMethod(method, args) { describe("methods-as-args", function() { it("should pass methods as arguments and have them still work", async function() { const { client } = await clientFor("helloWorld"); - const { result } = await callMethod(client.hello, { world: "tests" }); + const { result } = await callMethod(client.hello, { to: "tests" }); expect(result).to.deep.equal(["Hello", "tests"]); }); }); diff --git a/test/e2e/src/util.js b/test/e2e/src/util.js index 43d94ec56..81a865ce2 100644 --- a/test/e2e/src/util.js +++ b/test/e2e/src/util.js @@ -84,7 +84,7 @@ module.exports.friendbotUrl = friendbotUrl; async function generateFundedKeypair() { const keypair = Keypair.random(); - await fetch(`${friendbotUrl}/?addr=${keypair.publicKey()}`); + await fetch(friendbotUrl.indexOf('friendbot.stellar.org') !== -1 ? `${friendbotUrl}/?addr=${keypair.publicKey()}` : `${friendbotUrl}/friendbot?addr=${keypair.publicKey()}`); return keypair; } module.exports.generateFundedKeypair = generateFundedKeypair;