Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

chore: devnet to testnet #234

Merged
merged 2 commits into from
Apr 11, 2024
Merged
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
5 changes: 5 additions & 0 deletions schemas/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const transferTokensSchema = {
type: 'number',
minimum: 1,
},
denomination: {
type: 'string',
enum: ['IO', 'mIO'],
default: 'mIO',
},
},
required: ['target', 'qty'],
additionalProperties: false,
Expand Down
32 changes: 30 additions & 2 deletions src/actions/write/transferToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
INVALID_INPUT_MESSAGE,
} from '../../constants';
import { getBaselineState, stubbedArweaveTxId } from '../../tests/stubs';
import { IOToken } from '../../types';
import { IOToken, mIOToken } from '../../types';
import { transferTokens } from './transferTokens';

describe('transferTokens', () => {
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('transferTokens', () => {
);
});

it('should transfer balances if the user has sufficient balance', async () => {
it('should transfer balances if the user has sufficient balance using IO denomination', async () => {
const initialState = {
...getBaselineState(),
balances: {
Expand All @@ -76,6 +76,7 @@ describe('transferTokens', () => {
input: {
qty: new IOToken(100).valueOf(),
target: stubbedArweaveTxId,
denomination: 'IO',
},
});
expect(state).toEqual({
Expand All @@ -86,5 +87,32 @@ describe('transferTokens', () => {
},
});
});

it.each([undefined, { denomination: 'mIO' }])(
'should transfer balances if the user has sufficient balance using mIO denomination',
async (denomination: { denomination: string } | undefined) => {
const initialState = {
...getBaselineState(),
balances: {
test: new mIOToken(10_000).valueOf(),
},
};
const { state } = await transferTokens(initialState, {
caller: 'test',
input: {
qty: new mIOToken(100).valueOf(),
target: stubbedArweaveTxId,
...denomination,
},
});
expect(state).toEqual({
...initialState,
balances: {
test: new mIOToken(9900).valueOf(),
[stubbedArweaveTxId]: new mIOToken(100).valueOf(),
},
});
},
);
});
});
5 changes: 3 additions & 2 deletions src/actions/write/transferTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ export class TransferToken {
getInvalidAjvMessage(validateTransferToken, input, 'transferToken'),
);
}
const { target, qty } = input;
const { target, qty, denomination = 'mIO' } = input;
this.target = target;
this.qty = new IOToken(qty).toMIO();
this.qty =
denomination === 'mIO' ? new mIOToken(qty) : new IOToken(qty).toMIO();
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/transfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('Transfers', () => {
function: 'transfer',
target: targetAddress,
qty: TRANSFER_QTY.valueOf(),
denomination: 'IO',
});

expect(writeInteraction?.originalTxId).not.toBe(undefined);
Expand All @@ -69,6 +70,7 @@ describe('Transfers', () => {
function: 'transfer',
target: srcContractId, // The smartweave contract id acts as the protocol balance
qty: TRANSFER_QTY.valueOf(),
denomination: 'IO',
});

expect(writeInteraction?.originalTxId).not.toBe(undefined);
Expand Down Expand Up @@ -171,6 +173,7 @@ describe('Transfers', () => {
function: 'transfer',
target: targetAddress,
qty: TRANSFER_QTY.valueOf(),
denomination: 'IO',
});

expect(writeInteraction?.originalTxId).not.toBe(undefined);
Expand Down
1 change: 1 addition & 0 deletions tools/transfer-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
function: 'transfer',
target,
qty,
denomination: 'IO', // by default transfer in IO
},
{
disableBundling: true,
Expand Down
Loading