Skip to content

Commit

Permalink
chore(tests): seperate contract used in transfer, validate error mess…
Browse files Browse the repository at this point in the history
…ages in each test
  • Loading branch information
dtfiedler committed Dec 11, 2023
1 parent 1ff50ad commit 69984ce
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 34 deletions.
6 changes: 5 additions & 1 deletion tests/removeController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
10 changes: 6 additions & 4 deletions tests/removeRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
19 changes: 10 additions & 9 deletions tests/setController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ANTState>(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);
});
});
12 changes: 7 additions & 5 deletions tests/setName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
6 changes: 4 additions & 2 deletions tests/setRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
12 changes: 7 additions & 5 deletions tests/setTicker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
28 changes: 20 additions & 8 deletions tests/transfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<ANTState>(antContractTxId).connect(wallet);
});

Expand All @@ -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);
});
});

0 comments on commit 69984ce

Please sign in to comment.