Skip to content

Commit

Permalink
add manasharing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roaminro committed Dec 6, 2023
1 parent 9f2c74e commit 4e68844
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
3 changes: 1 addition & 2 deletions manasharing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"build:debug": "koinos-sdk-as-cli build-all --generate_authorize debug 0 manasharing.proto",
"build:release": "koinos-sdk-as-cli build-all --generate_authorize release 0 manasharing.proto",
"test": "koinos-sdk-as-cli run-tests",
"ci": "jest -i",
"ci:devcontainer": "ENV=DEVCONTAINER jest -i"
"ci": "jest -i"
}
}
72 changes: 60 additions & 12 deletions manasharing/tests/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { Contract, LocalKoinos } from '@roamin/local-koinos';
import { Contract, LocalKoinos, Signer, Token } from '@roamin/local-koinos';

import * as abi from '../abi/manasharing-abi.json';

Expand All @@ -10,7 +10,7 @@ jest.setTimeout(600000);

let localKoinos = new LocalKoinos();

if (process.env.ENV === 'DEVCONTAINER') {
if (process.env.DEVCONTAINER === 'true') {
localKoinos = new LocalKoinos({
rpc: 'http://host.docker.internal:8080',
amqp: 'amqp://host.docker.internal:5672'
Expand All @@ -20,10 +20,13 @@ if (process.env.ENV === 'DEVCONTAINER') {
const [
genesis,
koin,
contractAccount,
manasharingAccount,
tokenAAccount,
user1
] = localKoinos.getAccounts();

let contract: Contract;
let manasharingContract: Contract;
let tokenA: Token;

beforeAll(async () => {
// start local-koinos node
Expand All @@ -35,15 +38,22 @@ beforeAll(async () => {
await localKoinos.setNameServiceRecord('koin', koin.address, { mode: 'manual' });

// deploy wallet contract
contract = await localKoinos.deployContract(
contractAccount.wif,
manasharingContract = await localKoinos.deployContract(
manasharingAccount.wif,
'./build/release/contract.wasm',
// @ts-ignore abi is compatible
abi,
{ mode: 'manual' },
{
authorizesTransactionApplication: true
}
);

await localKoinos.startBlockProduction();

tokenA = new Token(tokenAAccount.address, tokenAAccount.signer);
let res = await tokenA.deploy();
await res.transaction.wait();
});

afterAll(async () => {
Expand All @@ -53,12 +63,50 @@ afterAll(async () => {


describe('integration-tests', () => {
it('runs the hello function', async () => {
const { result } = await contract.functions.hello({
name: 'me'
});

expect(result?.value).toEqual('Hello, me!');
it('allows for using the manashring contract mana', async () => {
expect.assertions(4)

const user3 = Signer.fromSeed('user3')

let res = await tokenA.mint(user3.address, 1);
await res.transaction.wait();

let bal = await tokenA.balanceOf(user3.address);
expect(bal).toStrictEqual("1");

bal = await tokenA.balanceOf(user1.address);
expect(bal).toStrictEqual("0");

try {
await tokenA.transfer(user3.address, user1.address, '1',
{
payer: user1.address,
beforeSend: async (tx) => {
tx.signatures = [];
await user3.signTransaction(tx);
},
}
);
} catch (error) {
expect(JSON.parse(error.message).error).toStrictEqual(
'account 1HYd2zqyWkDuKH26UYYNLwYGE6vhojCSqE has not authorized transaction'
);
}

res = await tokenA.transfer(user3.address, user1.address, '1',
{
payer: manasharingAccount.address,
beforeSend: async (tx) => {
tx.signatures = [];
await user3.signTransaction(tx);
},
}
);

await res.transaction.wait();

bal = await tokenA.balanceOf(user1.address);
expect(bal).toStrictEqual("1");
})

})

0 comments on commit 4e68844

Please sign in to comment.