UNPKG

5.38 kBJavaScriptView Raw
1
2const { Keygen } = require('eosjs-keygen');
3const ecc = require('eosjs-ecc');
4const { mockAction, mockOptions } = require('./helpers/eos');
5const { constructOrejs, mockGetTransaction } = require('./helpers/orejs');
6
7describe('createbridge', () => {
8 let spyTransaction;
9 let contractName = "createbridge";
10 let accountName = 'eosio';
11 let permission = 'active';
12 let authorizingAccount = {accountName, permission};
13 let appName = Math.random().toString();
14
15
16 beforeAll(() => {
17 orejs = constructOrejs();
18 });
19
20 describe('init', () => {
21 beforeEach(() => {
22 transaction = mockGetTransaction(orejs);
23 spyTransaction = jest.spyOn(orejs.eos, 'transact');
24 });
25
26 it('initialises createbridge', () => {
27 const symbol = "SYS";
28 const precision = 4;
29 const newAccountContract = "eosio";
30 const minimumRAM = 4096;
31 const options = {contractName};
32 orejs.init(symbol, precision, newAccountContract, minimumRAM, options);
33 expect(spyTransaction).toHaveBeenCalledWith({
34 actions: [
35 mockAction({account: contractName, name:"init", authorization: { actor: contractName, permission }, data:{
36 symbol: precision+","+symbol,
37 newaccountcontract: newAccountContract,
38 minimumram: minimumRAM,
39 }})
40 ]
41 },mockOptions());
42 });
43 });
44
45 describe('define', () => {
46
47 beforeEach(() => {
48 transaction = mockGetTransaction(orejs);
49 spyTransaction = jest.spyOn(orejs.eos, 'transact');
50 });
51
52 it('registers an app with createbridge', () => {
53 const ram = 4096;
54 const net = "1.0000 SYS";
55 const cpu = "1.0000 SYS";
56 const airdropContract = "";
57 const airdropToken = "0 SYS";
58 const airdropLimit = "0 SYS";
59 const options = {airdropContract, airdropToken, airdropLimit, contractName};
60 orejs.define(authorizingAccount, appName, ram, net, cpu, options);
61 expect(spyTransaction).toHaveBeenCalledWith({
62 actions: [
63 mockAction({account: contractName, name:"define", authorization: { permission }, data:{
64 owner: accountName,
65 dapp: appName,
66 ram_bytes: ram,
67 net: net,
68 cpu: cpu,
69 airdrop: {
70 contract: airdropContract,
71 tokens: airdropToken,
72 limit: airdropLimit
73 },
74 }})
75 ]
76 },mockOptions());
77 });
78 });
79
80 describe('whitelist', () => {
81 beforeEach(() => {
82 transaction = mockGetTransaction(orejs);
83 spyTransaction = jest.spyOn(orejs.eos, 'transact');
84 });
85
86 it('whitelist an account as a custodian for an app', () => {
87 const whitelistAccount = 'app.oreid';
88 const options = {contractName};
89 orejs.whitelist(authorizingAccount, whitelistAccount, appName,options);
90 expect(spyTransaction).toHaveBeenCalledWith({
91 actions: [
92 mockAction({account: contractName, name:"whitelist", authorization: { permission }, data:{
93 owner: accountName,
94 account: whitelistAccount,
95 dapp: appName,
96 }})
97 ]
98 },mockOptions());
99 });
100 });
101
102 describe('transfer', () => {
103 beforeEach(() => {
104 transaction = mockGetTransaction(orejs);
105 spyTransaction = jest.spyOn(orejs.eos, 'transact');
106 });
107
108 it('transfers the contribution amount from the contributor to createbridge', () => {
109 const amount = "1.000 SYS";
110 const ramPercentage = 50;
111 const totalAccounts = 10;
112 const options = {contractName};
113 orejs.transfer(authorizingAccount, appName, amount, ramPercentage, totalAccounts,options);
114 expect(spyTransaction).toHaveBeenCalledWith({
115 actions: [
116 mockAction({account: contractName, name:"transfer", authorization: { permission }, data:{
117 from: accountName,
118 to: "createbridge",
119 quantity: amount,
120 memo: appName + "," + ramPercentage + "," + totalAccounts,
121 }})
122 ]
123 },mockOptions());
124 });
125 });
126
127 describe('reclaim', () => {
128 beforeEach(() => {
129 transaction = mockGetTransaction(orejs);
130 spyTransaction = jest.spyOn(orejs.eos, 'transact');
131 });
132
133 it('reclaims the contributor\'s remaining core token balance from createbridge', () => {
134 const symbol = 'SYS';
135 const options = {contractName};
136 orejs.reclaim(authorizingAccount, appName, symbol,options);
137 expect(spyTransaction).toHaveBeenCalledWith({
138 actions: [
139 mockAction({account: contractName, name:"reclaim", authorization: { permission }, data:{
140 reclaimer: accountName,
141 dapp: appName,
142 sym: symbol,
143 }})
144 ]
145 },mockOptions());
146 })
147
148 it('reclaims the contributor\'s remaining app token balance from createbridge', () => {
149 // example app token
150 const symbol = 'EX';
151 const options = {contractName};
152 orejs.reclaim(authorizingAccount, appName, symbol,options);
153 expect(spyTransaction).toHaveBeenCalledWith({
154 actions: [
155 mockAction({account: contractName, name:"reclaim", authorization: { permission }, data:{
156 reclaimer: accountName,
157 dapp: appName,
158 sym: symbol,
159 }})
160 ]
161 },mockOptions());
162 });
163 });
164});
\No newline at end of file