@@ -1084,3 +1084,66 @@ test('withdraw using planner', async t => {
1084
1084
] ) ;
1085
1085
t . is ( 833332500n , ( 3333330000n * 25n ) / 100n ) ;
1086
1086
} ) ;
1087
+
1088
+ test ( 'creatorFacet.withdrawFees' , async t => {
1089
+ const { started, common } = await setupTrader ( t ) ;
1090
+ const { storage } = common . bootstrap ;
1091
+ const { inspectLocalBridge } = common . utils ;
1092
+
1093
+ const { contractAccount } = storage
1094
+ . getDeserialized ( `${ ROOT_STORAGE_PATH } ` )
1095
+ . at ( - 1 ) as unknown as { contractAccount : string } ;
1096
+ t . log ( 'contractAddress for fees' , contractAccount ) ;
1097
+
1098
+ const { bld } = common . brands ;
1099
+ const bld2k = bld . units ( 2_000 ) ;
1100
+ {
1101
+ const pmt = await common . utils . pourPayment ( bld2k ) ;
1102
+ const { bankManager } = common . bootstrap ;
1103
+ const bank = E ( bankManager ) . getBankForAddress ( contractAccount ) ;
1104
+ const purse = E ( bank ) . getPurse ( bld2k . brand ) ;
1105
+ await E ( purse ) . deposit ( pmt ) ;
1106
+ t . log ( 'deposited' , bld2k , 'for fees' ) ;
1107
+ }
1108
+
1109
+ const { creatorFacet } = started ;
1110
+
1111
+ const dest = `cosmos:agoric-3:${ makeTestAddress ( 5 ) } ` as const ;
1112
+
1113
+ {
1114
+ const actual = await E ( creatorFacet ) . withdrawFees ( dest , {
1115
+ denom : 'ubld' ,
1116
+ value : 100n ,
1117
+ } ) ;
1118
+ t . log ( 'withdrew some' , actual ) ;
1119
+
1120
+ t . deepEqual ( actual , { denom : 'ubld' , value : 100n } ) ;
1121
+
1122
+ const [ tx ] = inspectLocalBridge ( ) . filter (
1123
+ obj => obj . type === 'VLOCALCHAIN_EXECUTE_TX' ,
1124
+ ) ;
1125
+ t . like ( tx . messages [ 0 ] , {
1126
+ '@type' : '/cosmos.bank.v1beta1.MsgSend' ,
1127
+ fromAddress : 'agoric1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp7zqht' ,
1128
+ toAddress : 'agoric1q5qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq8ee25y' ,
1129
+ amount : [ { denom : 'ubld' , amount : '100' } ] ,
1130
+ } ) ;
1131
+ }
1132
+
1133
+ {
1134
+ const amt = await E ( creatorFacet ) . withdrawFees ( dest ) ;
1135
+
1136
+ t . log ( 'withdrew all' , amt ) ;
1137
+ t . deepEqual ( amt , { denom : 'ubld' , value : bld2k . value } ) ;
1138
+
1139
+ const [ _ , tx ] = inspectLocalBridge ( ) . filter (
1140
+ obj => obj . type === 'VLOCALCHAIN_EXECUTE_TX' ,
1141
+ ) ;
1142
+ t . like ( tx . messages [ 0 ] , {
1143
+ '@type' : '/cosmos.bank.v1beta1.MsgSend' ,
1144
+ fromAddress : 'agoric1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp7zqht' ,
1145
+ toAddress : 'agoric1q5qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq8ee25y' ,
1146
+ amount : [ { denom : 'ubld' , amount : '2000000000' } ] ,
1147
+ } ) ;
1148
+ }
1149
+ } ) ;
0 commit comments