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

fix(contract-client): stop jsifying method names #928

Closed
wants to merge 1 commit into from
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/contract_client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import { ContractSpec, xdr } from '..'
import { AssembledTransaction } from './assembled_transaction'
import type { ContractClientOptions, MethodOptions } from './types'

/**
* converts a snake_case string to camelCase
*/
function toLowerCamelCase(str: string): string {
return str.replace(/_\w/g, (m) => m[1].toUpperCase());
}

export class ContractClient {
/**
* Generate a class from the contract spec that where each contract method
Expand All @@ -25,9 +18,8 @@ export class ContractClient {
let methods = this.spec.funcs();
for (let method of methods) {
let name = method.name().toString();
let jsName = toLowerCamelCase(name);
// @ts-ignore
this[jsName] = async (
this[name] = async (
args: Record<string, any>,
options: MethodOptions
) => {
Expand Down
17 changes: 10 additions & 7 deletions test/e2e/src/test-custom-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ test('woid', async t => {

test('u32_fail_on_even', async t => {
t.deepEqual(
(await t.context.client.u32FailOnEven({ u32_: 1 })).result,
(await t.context.client.u32_fail_on_even({ u32_: 1 })).result,
new Ok(1)
)
t.deepEqual(
(await t.context.client.u32FailOnEven({ u32_: 2 })).result,
(await t.context.client.u32_fail_on_even({ u32_: 2 })).result,
new Err({ message: "Please provide an odd number" })
)
})
Expand All @@ -44,7 +44,7 @@ test('i64', async t => {

test("strukt_hel", async (t) => {
const strukt = { a: 0, b: true, c: "world" }
t.deepEqual((await t.context.client.struktHel({ strukt })).result, ["Hello", "world"])
t.deepEqual((await t.context.client.strukt_hel({ strukt })).result, ["Hello", "world"])
})

test("strukt", async (t) => {
Expand Down Expand Up @@ -109,7 +109,10 @@ test('bytes', async t => {

test('bytesN', async t => {
const bytesN = Buffer.from('123456789') // what's the correct way to construct bytesN?
t.deepEqual((await t.context.client.bytesN({ bytes_n: bytesN })).result, bytesN)
t.deepEqual(
(await t.context.client.bytes_n({ bytes_n: bytesN })).result,
bytesN
)
})

test('card', async t => {
Expand All @@ -134,8 +137,8 @@ test('u128', async t => {
})

test('multi_args', async t => {
t.is((await t.context.client.multiArgs({ a: 1, b: true })).result, 1)
t.is((await t.context.client.multiArgs({ a: 1, b: false })).result, 0)
t.is((await t.context.client.multi_args({ a: 1, b: true })).result, 1)
t.is((await t.context.client.multi_args({ a: 1, b: false })).result, 0)
})

test('map', async t => {
Expand Down Expand Up @@ -184,5 +187,5 @@ test('string', async t => {
test('tuple_strukt', async t => {
const arg = [{ a: 0, b: true, c: 'hello' }, { tag: 'First', values: undefined }]
const res = [{ a: 0, b: true, c: 'hello' }, { tag: 'First' }]
t.deepEqual((await t.context.client.tupleStrukt({ tuple_strukt: arg })).result, res)
t.deepEqual((await t.context.client.tuple_strukt({ tuple_strukt: arg })).result, res)
})
4 changes: 2 additions & 2 deletions test/e2e/src/test-hello-world.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ test("auth", async (t) => {

test("inc", async (t) => {
const { client } = await clientFor('helloWorld')
const { result: startingBalance } = await client.getCount()
const { result: startingBalance } = await client.get_count()
const inc = await client.inc()
t.is((await inc.signAndSend()).result, startingBalance + 1)
t.is(startingBalance, 0)
t.is((await client.getCount()).result, startingBalance + 1)
t.is((await client.get_count()).result, startingBalance + 1)
});
Loading