1+ import {
2+ State ,
3+ state ,
4+ UInt64 ,
5+ Bool ,
6+ SmartContract ,
7+ Mina ,
8+ AccountUpdate ,
9+ method ,
10+ PublicKey ,
11+ Permissions ,
12+ VerificationKey ,
13+ Field ,
14+ Int64 ,
15+ TokenId ,
16+ TokenContract as TokenContractBase ,
17+ AccountUpdateForest ,
18+ PrivateKey ,
19+ } from 'o1js' ;
20+ import { test , describe , it , before } from 'node:test' ;
21+ import { expect } from 'expect' ;
22+
23+
24+
25+ const defaultNetwork = Mina . Network ( {
26+ networkId : "testnet" ,
27+ mina : "https://example.com/graphql" ,
28+ archive : "https://example.com//graphql"
29+ } ) ;
30+
31+ const enforcedNetwork = Mina . Network ( {
32+ networkId : "testnet" ,
33+ mina : "https://example.com/graphql" ,
34+ archive : "https://example.com//graphql" ,
35+ bypassTransactionLimits : false
36+ } ) ;
37+
38+ const unlimitedNetwork = Mina . Network ( {
39+ networkId : "testnet" ,
40+ mina : "https://unlimited.com/graphql" ,
41+ archive : "https://unlimited.com//graphql" ,
42+ bypassTransactionLimits : true
43+ } ) ;
44+
45+ describe ( 'Test default network' , ( ) => {
46+ let bobAccount : PublicKey ,
47+ bobKey : PrivateKey ;
48+
49+ before ( async ( ) => {
50+
51+ Mina . setActiveInstance ( defaultNetwork ) ;
52+ bobKey = PrivateKey . random ( ) ;
53+ bobAccount = bobKey . toPublicKey ( ) ;
54+ } ) ;
55+
56+
57+ it ( 'Simple account update' , async ( ) => {
58+
59+ let txn = await Mina . transaction ( async ( ) => {
60+ const accountUpdateBob = AccountUpdate . create ( bobAccount , Field . from ( 1 ) ) ;
61+ accountUpdateBob . account . balance . requireEquals ( UInt64 . zero ) ;
62+ accountUpdateBob . balance . addInPlace ( UInt64 . one ) ;
63+ } ) ;
64+ await txn . prove ( ) ;
65+ await txn . sign ( [ bobKey ] ) . safeSend ( ) ;
66+
67+ } ) ;
68+
69+ it ( 'Multiple account update' , async ( ) => {
70+
71+ let txn = await Mina . transaction ( async ( ) => {
72+ for ( let index = 0 ; index < 2 ; index ++ ) {
73+ const accountUpdateBob = AccountUpdate . create ( bobAccount , Field . from ( index ) ) ;
74+ accountUpdateBob . account . balance . requireEquals ( UInt64 . zero ) ;
75+ accountUpdateBob . balance . addInPlace ( UInt64 . one ) ;
76+ }
77+ } ) ;
78+ await txn . prove ( ) ;
79+ await txn . sign ( [ bobKey ] ) . safeSend ( ) ;
80+
81+ } ) ;
82+
83+ it ( 'More than limit account update' , async ( ) => {
84+
85+ let txn = await Mina . transaction ( async ( ) => {
86+ for ( let index = 0 ; index < 12 ; index ++ ) {
87+ const accountUpdateBob = AccountUpdate . create ( bobAccount , Field . from ( index ) ) ;
88+ accountUpdateBob . account . balance . requireEquals ( UInt64 . zero ) ;
89+ accountUpdateBob . balance . addInPlace ( UInt64 . one ) ;
90+ }
91+ } ) ;
92+ await txn . prove ( ) ;
93+ // failure with default bypassTransactionLimits value
94+ await expect ( txn . sign ( [ bobKey ] ) . safeSend ( ) ) . rejects . toThrow ( ) ;
95+ } ) ;
96+ } ) ;
97+
98+ describe ( 'Test enforced network' , ( ) => {
99+ let bobAccount : PublicKey ,
100+ bobKey : PrivateKey ;
101+
102+ before ( async ( ) => {
103+
104+ Mina . setActiveInstance ( enforcedNetwork ) ;
105+ bobKey = PrivateKey . random ( ) ;
106+ bobAccount = bobKey . toPublicKey ( ) ;
107+ } ) ;
108+
109+
110+ it ( 'Simple account update' , async ( ) => {
111+
112+ let txn = await Mina . transaction ( async ( ) => {
113+ const accountUpdateBob = AccountUpdate . create ( bobAccount , Field . from ( 1 ) ) ;
114+ accountUpdateBob . account . balance . requireEquals ( UInt64 . zero ) ;
115+ accountUpdateBob . balance . addInPlace ( UInt64 . one ) ;
116+ } ) ;
117+ await txn . prove ( ) ;
118+ await txn . sign ( [ bobKey ] ) . safeSend ( ) ;
119+
120+ } ) ;
121+
122+ it ( 'Multiple account update' , async ( ) => {
123+
124+ let txn = await Mina . transaction ( async ( ) => {
125+ for ( let index = 0 ; index < 2 ; index ++ ) {
126+ const accountUpdateBob = AccountUpdate . create ( bobAccount , Field . from ( index ) ) ;
127+ accountUpdateBob . account . balance . requireEquals ( UInt64 . zero ) ;
128+ accountUpdateBob . balance . addInPlace ( UInt64 . one ) ;
129+ }
130+ } ) ;
131+ await txn . prove ( ) ;
132+ await txn . sign ( [ bobKey ] ) . safeSend ( ) ;
133+
134+ } ) ;
135+
136+ it ( 'More than limit account update' , async ( ) => {
137+
138+ let txn = await Mina . transaction ( async ( ) => {
139+ for ( let index = 0 ; index < 12 ; index ++ ) {
140+ const accountUpdateBob = AccountUpdate . create ( bobAccount , Field . from ( index ) ) ;
141+ accountUpdateBob . account . balance . requireEquals ( UInt64 . zero ) ;
142+ accountUpdateBob . balance . addInPlace ( UInt64 . one ) ;
143+ }
144+ } ) ;
145+ await txn . prove ( ) ;
146+ // failure with bypassTransactionLimits = false
147+ await expect ( txn . sign ( [ bobKey ] ) . safeSend ( ) ) . rejects . toThrow ( ) ;
148+ } ) ;
149+ } ) ;
150+
151+ describe ( 'Test unlimited network' , ( ) => {
152+ let bobAccount : PublicKey ,
153+ bobKey : PrivateKey ;
154+
155+ before ( async ( ) => {
156+
157+ Mina . setActiveInstance ( unlimitedNetwork ) ;
158+ bobKey = PrivateKey . random ( ) ;
159+ bobAccount = bobKey . toPublicKey ( ) ;
160+ } ) ;
161+
162+
163+ it ( 'Simple account update' , async ( ) => {
164+
165+ let txn = await Mina . transaction ( async ( ) => {
166+ const accountUpdateBob = AccountUpdate . create ( bobAccount , Field . from ( 1 ) ) ;
167+ accountUpdateBob . account . balance . requireEquals ( UInt64 . zero ) ;
168+ accountUpdateBob . balance . addInPlace ( UInt64 . one ) ;
169+ } ) ;
170+ await txn . prove ( ) ;
171+ await txn . sign ( [ bobKey ] ) . safeSend ( ) ;
172+
173+ } ) ;
174+
175+ it ( 'Multiple account update' , async ( ) => {
176+
177+ let txn = await Mina . transaction ( async ( ) => {
178+ for ( let index = 0 ; index < 2 ; index ++ ) {
179+ const accountUpdateBob = AccountUpdate . create ( bobAccount , Field . from ( index ) ) ;
180+ accountUpdateBob . account . balance . requireEquals ( UInt64 . zero ) ;
181+ accountUpdateBob . balance . addInPlace ( UInt64 . one ) ;
182+ }
183+ } ) ;
184+ await txn . prove ( ) ;
185+ await txn . sign ( [ bobKey ] ) . safeSend ( ) ;
186+
187+ } ) ;
188+
189+ it ( 'More than limit account update' , async ( ) => {
190+
191+ let txn = await Mina . transaction ( async ( ) => {
192+ for ( let index = 0 ; index < 12 ; index ++ ) {
193+ const accountUpdateBob = AccountUpdate . create ( bobAccount , Field . from ( index ) ) ;
194+ accountUpdateBob . account . balance . requireEquals ( UInt64 . zero ) ;
195+ accountUpdateBob . balance . addInPlace ( UInt64 . one ) ;
196+ }
197+ } ) ;
198+ await txn . prove ( ) ;
199+ // success with bypassTransactionLimits = true
200+ await txn . sign ( [ bobKey ] ) . safeSend ( ) ;
201+ } ) ;
202+ } ) ;
0 commit comments