From 69984ce914cde2c0bbde43a800ffbaf127b5e41f Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 11 Dec 2023 08:15:21 -0800 Subject: [PATCH] chore(tests): seperate contract used in transfer, validate error messages in each test --- tests/removeController.test.ts | 6 +++++- tests/removeRecord.test.ts | 10 ++++++---- tests/setController.test.ts | 19 ++++++++++--------- tests/setName.test.ts | 12 +++++++----- tests/setRecord.test.ts | 6 ++++-- tests/setTicker.test.ts | 12 +++++++----- tests/transfer.test.ts | 28 ++++++++++++++++++++-------- 7 files changed, 59 insertions(+), 34 deletions(-) diff --git a/tests/removeController.test.ts b/tests/removeController.test.ts index df53b6d..5f4b1b2 100644 --- a/tests/removeController.test.ts +++ b/tests/removeController.test.ts @@ -30,13 +30,17 @@ describe('removeController', () => { }); it('should remove controller from the ANT', async () => { + const controller = 'someothertransactionidforwalletandcontract1'; const writeInteraction = await contract.writeInteraction({ function: 'removeController', - target: antContractOwnerAddress, + target: controller, }); expect(writeInteraction?.originalTxId).toBeDefined(); const { cachedValue } = await contract.readState(); + expect( + cachedValue?.errorMessages[writeInteraction?.originalTxId], + ).toBeUndefined(); expect(cachedValue.state.controllers[antContractOwnerAddress]).toEqual( undefined, ); diff --git a/tests/removeRecord.test.ts b/tests/removeRecord.test.ts index 71a56e5..1b8b525 100644 --- a/tests/removeRecord.test.ts +++ b/tests/removeRecord.test.ts @@ -29,13 +29,15 @@ describe('removeRecord', () => { it('should remove test record from the ANT', async () => { const subDomain = 'remove'; - const result = await contract.writeInteraction({ + const writeInteraction = await contract.writeInteraction({ function: 'removeRecord', subDomain, }); - expect(result?.originalTxId).toBeDefined(); + expect(writeInteraction?.originalTxId).toBeDefined(); const { cachedValue } = await contract.readState(); - const state = cachedValue.state; - expect(state.records[subDomain]).toBeUndefined(); + expect( + cachedValue?.errorMessages[writeInteraction?.originalTxId], + ).toBeUndefined(); + expect(cachedValue.state.records[subDomain]).toBeUndefined(); }); }); diff --git a/tests/setController.test.ts b/tests/setController.test.ts index 90d1af9..10a86dd 100644 --- a/tests/setController.test.ts +++ b/tests/setController.test.ts @@ -19,27 +19,28 @@ import { arweave, getLocalWallet, warp } from './utils/helper'; describe('setController', () => { let antContractTxId: string; - let antContractOwnerAddress: string; let contract; beforeEach(async () => { - const { wallet, address } = await getLocalWallet(arweave); - antContractOwnerAddress = address; + const { wallet } = await getLocalWallet(arweave); antContractTxId = process.env.ANT_CONTRACT_TX_ID; contract = warp.contract(antContractTxId).connect(wallet); }); it('should add controller to the ANT', async () => { - const result = await contract.writeInteraction({ + const newController = 'someothertransactionidforwalletandcontract2'; + const writeInteraction = await contract.writeInteraction({ function: 'setController', - target: antContractOwnerAddress, + target: newController, }); - expect(result).toBeDefined(); - expect(result?.originalTxId).toBeDefined(); + expect(writeInteraction).toBeDefined(); + expect(writeInteraction?.originalTxId).toBeDefined(); const { cachedValue } = await contract.readState(); - const state = cachedValue.state; - expect(state.controllers).toContain(antContractOwnerAddress); + expect( + cachedValue?.errorMessages[writeInteraction?.originalTxId], + ).toBeUndefined(); + expect(cachedValue.state.controllers).toContain(newController); }); }); diff --git a/tests/setName.test.ts b/tests/setName.test.ts index 4182f42..ec98e21 100644 --- a/tests/setName.test.ts +++ b/tests/setName.test.ts @@ -32,16 +32,18 @@ describe('setName', () => { it('should set the name of the ANT', async () => { const name = 'my-new-name'; - const result = await contract.writeInteraction({ + const writeInteraction = await contract.writeInteraction({ function: 'setName', name, }); - expect(result).toBeDefined(); - expect(result?.originalTxId).toBeDefined(); + expect(writeInteraction).toBeDefined(); + expect(writeInteraction?.originalTxId).toBeDefined(); const { cachedValue } = await contract.readState(); - const state = cachedValue.state; - expect(state.name).toEqual(name); + expect( + cachedValue?.errorMessages[writeInteraction?.originalTxId], + ).toBeUndefined(); + expect(cachedValue.state.name).toEqual(name); }); }); diff --git a/tests/setRecord.test.ts b/tests/setRecord.test.ts index 9355099..90b95bb 100644 --- a/tests/setRecord.test.ts +++ b/tests/setRecord.test.ts @@ -44,8 +44,10 @@ describe('Testing setRecord...', () => { expect(writeInteraction?.originalTxId).toBeDefined(); const { cachedValue } = await contract.readState(); - const state = cachedValue.state; - expect(state.records[subDomain]).toEqual({ + expect( + cachedValue?.errorMessages[writeInteraction?.originalTxId], + ).toBeUndefined(); + expect(cachedValue.state.records[subDomain]).toEqual({ transactionId: antContractOwnerAddress, ttlSeconds: MIN_TTL_LENGTH, }); diff --git a/tests/setTicker.test.ts b/tests/setTicker.test.ts index d9cef3c..647e35c 100644 --- a/tests/setTicker.test.ts +++ b/tests/setTicker.test.ts @@ -29,16 +29,18 @@ describe('setTicker', () => { it('should set the ticker of the ANT', async () => { const ticker = 'TICK'; - const result = await contract.writeInteraction({ + const writeInteraction = await contract.writeInteraction({ function: 'setTicker', ticker, }); - expect(result).toBeDefined(); - expect(result?.originalTxId).toBeDefined(); + expect(writeInteraction).toBeDefined(); + expect(writeInteraction?.originalTxId).toBeDefined(); const { cachedValue } = await contract.readState(); - const state = cachedValue.state; - expect(state.ticker).toEqual(ticker); + expect( + cachedValue?.errorMessages[writeInteraction?.originalTxId], + ).toBeUndefined(); + expect(cachedValue.state.ticker).toEqual(ticker); }); }); diff --git a/tests/transfer.test.ts b/tests/transfer.test.ts index 49fdd17..7608a5d 100644 --- a/tests/transfer.test.ts +++ b/tests/transfer.test.ts @@ -15,17 +15,27 @@ * along with this program. If not, see . */ import { ANTState } from '../src/types'; -import { arweave, getLocalWallet, warp } from './utils/helper'; +import { + arweave, + deployANTContract, + getLocalWallet, + warp, +} from './utils/helper'; describe('transfer', () => { - let antContractTxId: string; let antContractOwnerAddress: string; + let antContractTxId: string; let contract; beforeEach(async () => { const { wallet, address } = await getLocalWallet(arweave); - antContractOwnerAddress = address; - antContractTxId = process.env.ANT_CONTRACT_TX_ID; + // deploy a separate contract for this test + const { contractTxId } = await deployANTContract({ + warp, + owner: address, + wallet, + }); + antContractTxId = contractTxId; contract = warp.contract(antContractTxId).connect(wallet); }); @@ -37,9 +47,11 @@ describe('transfer', () => { }); expect(writeInteraction?.originalTxId).not.toBe(undefined); - const { cachedValue: newCachedValue } = await contract.readState(); - const newState = newCachedValue.state as ANTState; - expect(newState.balances[antContractOwnerAddress]).toEqual(undefined); - expect(newState.balances[target]).toEqual(1); + const { cachedValue } = await contract.readState(); + expect(cachedValue.state.balances[antContractOwnerAddress]).toEqual( + undefined, + ); + expect(cachedValue.state.balances[target]).toEqual(1); + expect(cachedValue.state.owner).toEqual(target); }); });