@@ -29,6 +29,8 @@ import { rename, stat } from 'node:fs/promises';
2929
3030export var NUMBER_OF_CANDIDATES = 7 ;
3131
32+ type config_type = Partial < { planet : Account ; vote_weight_account : Account } > ;
33+
3234export class SharedTestObjects {
3335 // Shared Instances to use between tests.
3436 private static instance : SharedTestObjects ;
@@ -169,7 +171,7 @@ export class SharedTestObjects {
169171 dacId : string ,
170172 symbol : string ,
171173 initialAsset : string ,
172- config ?: any
174+ config ?: config_type
173175 ) {
174176 await this . setup_new_auth_account ( ) ;
175177 // Further setup after the inital singleton object have been created.
@@ -305,7 +307,7 @@ export class SharedTestObjects {
305307 private async register_dac_with_directory (
306308 dacId : string ,
307309 tokenSymbol : string ,
308- config ?: any
310+ config ?: config_type
309311 ) {
310312 const accounts = [
311313 {
@@ -325,18 +327,87 @@ export class SharedTestObjects {
325327 value : this . referendum_contract . account . name ,
326328 } ,
327329 ] ;
328- if ( config && config . planet ) {
329- accounts . push ( {
330- key : Account_type . MSIGOWNED ,
331- value : config . planet . name ,
332- } ) ;
333- }
334- if ( config && config . vote_weight_account ) {
335- console . log ( 'adding ' , config . vote_weight_account . name ) ;
336- accounts . push ( {
337- key : Account_type . VOTING ,
338- value : config . vote_weight_account . name ,
339- } ) ;
330+ if ( config ) {
331+ if ( config . planet ) {
332+ accounts . push ( {
333+ key : Account_type . MSIGOWNED ,
334+ value : config . planet . name ,
335+ } ) ;
336+ accounts . push ( {
337+ key : Account_type . SPENDINGS ,
338+ value : config . planet . name ,
339+ } ) ;
340+ await debugPromise (
341+ UpdateAuth . execUpdateAuth (
342+ [ { actor : config . planet . name , permission : 'active' } ] ,
343+ config . planet . name ,
344+ 'escrow' ,
345+ 'active' ,
346+ UpdateAuth . AuthorityToSet . forContractCode (
347+ this . dacproposals_contract . account
348+ )
349+ ) ,
350+ 'add escrow auth'
351+ ) ;
352+
353+ await debugPromise (
354+ UpdateAuth . execUpdateAuth (
355+ [ { actor : config . planet . name , permission : 'active' } ] ,
356+ config . planet . name ,
357+ 'xfer' ,
358+ 'active' ,
359+ UpdateAuth . AuthorityToSet . forContractCode (
360+ this . dacproposals_contract . account
361+ )
362+ ) ,
363+ 'add xfer to SPENDINGS'
364+ ) ;
365+ await UpdateAuth . execLinkAuth (
366+ [ { actor : config . planet . name , permission : 'active' } ] ,
367+ config . planet . name ,
368+ this . dacescrow_contract . account . name ,
369+ 'init' ,
370+ 'escrow'
371+ ) ;
372+
373+ await debugPromise (
374+ UpdateAuth . execLinkAuth (
375+ [ { actor : config . planet . name , permission : 'active' } ] ,
376+ config . planet . name ,
377+ this . dacescrow_contract . account . name ,
378+ 'approve' ,
379+ 'escrow'
380+ ) ,
381+ 'linking escrow perm to planet spendings'
382+ ) ;
383+ await debugPromise (
384+ UpdateAuth . execLinkAuth (
385+ [ { actor : config . planet . name , permission : 'active' } ] ,
386+ config . planet . name ,
387+ this . dac_token_contract . account . name ,
388+ 'transfer' ,
389+ 'xfer'
390+ ) ,
391+ 'linking xfer perm to transfer tokens'
392+ ) ;
393+ await debugPromise (
394+ UpdateAuth . execLinkAuth (
395+ [ { actor : config . planet . name , permission : 'active' } ] ,
396+ config . planet . name ,
397+ 'eosio.token' ,
398+ 'transfer' ,
399+ 'xfer'
400+ ) ,
401+ 'linking xfer perm to transfer tokens'
402+ ) ;
403+ }
404+ if ( config . vote_weight_account ) {
405+ console . log ( 'adding ' , config . vote_weight_account . name ) ;
406+ accounts . push ( {
407+ key : Account_type . VOTING ,
408+ value : config . vote_weight_account . name ,
409+ } ) ;
410+ }
340411 }
341412
342413 await this . dacdirectory_contract . regdac (
@@ -411,45 +482,14 @@ export class SharedTestObjects {
411482 'add xfer auth to eosdactoken'
412483 ) ;
413484
414- await debugPromise (
415- UpdateAuth . execUpdateAuth (
416- this . treasury_account . active ,
417- this . treasury_account . name ,
418- 'escrow' ,
419- 'active' ,
420- UpdateAuth . AuthorityToSet . forContractCode (
421- this . dacproposals_contract . account
422- )
423- ) ,
424- 'add escrow auth'
425- ) ;
426-
427485 await debugPromise (
428486 UpdateAuth . execUpdateAuth (
429487 this . treasury_account . active ,
430488 this . treasury_account . name ,
431489 'xfer' ,
432490 'active' ,
433- UpdateAuth . AuthorityToSet . explicitAuthorities (
434- 1 ,
435- [
436- {
437- permission : {
438- actor : this . daccustodian_contract . account . name ,
439- permission : 'eosio.code' ,
440- } ,
441- weight : 1 ,
442- } ,
443- {
444- permission : {
445- actor : this . dacproposals_contract . account . name ,
446- permission : 'eosio.code' ,
447- } ,
448- weight : 1 ,
449- } ,
450- ] ,
451- [ ] ,
452- [ ]
491+ UpdateAuth . AuthorityToSet . forContractCode (
492+ this . daccustodian_contract . account
453493 )
454494 ) ,
455495 'add xfer to treasury'
@@ -536,25 +576,6 @@ export class SharedTestObjects {
536576 'notify'
537577 ) ;
538578
539- await UpdateAuth . execLinkAuth (
540- this . treasury_account . active ,
541- this . treasury_account . name ,
542- this . dacescrow_contract . account . name ,
543- 'init' ,
544- 'escrow'
545- ) ;
546-
547- await debugPromise (
548- UpdateAuth . execLinkAuth (
549- this . treasury_account . active ,
550- this . treasury_account . name ,
551- this . dacescrow_contract . account . name ,
552- 'approve' ,
553- 'escrow'
554- ) ,
555- 'linking escrow perm to treasury'
556- ) ;
557-
558579 await UpdateAuth . execLinkAuth (
559580 this . treasury_account . active ,
560581 this . treasury_account . name ,
@@ -976,6 +997,7 @@ export enum Account_type {
976997 VOTING = 8 ,
977998 ACTIVATION = 9 ,
978999 REFERENDUM = 10 ,
1000+ SPENDINGS = 11 ,
9791001 EXTERNAL = 254 ,
9801002 OTHER = 255 ,
9811003}
0 commit comments