Skip to content

Commit

Permalink
feat: change contractName default behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Dec 10, 2022
1 parent 75392f8 commit 15a3f18
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-news-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"clarigen-deno": patch
---

Updated `contractFactory` behavior - now all contract calls will have the full identifier - not just the contractName.
2 changes: 1 addition & 1 deletion src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function contractFactory<T extends TypedAbi>(
abi: T,
identifier: string,
) {
const full = { ...abi } as FullContract<T>;
const full = { ...abi, contractName: identifier } as FullContract<T>;
full.identifier = identifier;
return {
...functionsFactory(abi.functions, identifier),
Expand Down
17 changes: 15 additions & 2 deletions test_pkg/factory_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertEquals } from '../src/deps.ts';
import { contractsFactory } from '../src/factory.ts';
import { contractFactory, contractsFactory } from '../src/factory.ts';
import {
contracts as _contracts,
simnet,
Expand All @@ -17,7 +17,7 @@ Deno.test('contracts factory', () => {

const call = tester.square(2n);
assertEquals(call.args, [types.uint(2n)]);
assertEquals(call.contract, testerDef.contractName);
assertEquals(call.contract.split('.')[1], testerDef.contractName);
assertEquals(call.fn.name, 'square');

const callRecord = tester.square({ n: 2 });
Expand All @@ -28,3 +28,16 @@ Deno.test('contracts factory', () => {
types.tuple({ 'min-height': 'u1' }),
]);
});

Deno.test({
name: 'contractFactory',
fn() {
const alice = simnet.accounts.wallet_1.address;
const id = `${alice}.${_contracts.counter.contractName}`;
const counter = contractFactory(_contracts.counter, id);
assertEquals(counter.contractName, id);
assertEquals(counter.identifier, id);
const fn = counter.getCounter();
assertEquals(fn.contract, id);
},
});

0 comments on commit 15a3f18

Please sign in to comment.