1
1
import * as Crypto from '@cardano-sdk/crypto' ;
2
2
import { Cardano } from '../../../src' ;
3
+ import { Ed25519KeyHashHex } from '@cardano-sdk/crypto' ;
3
4
4
5
describe ( 'Cardano.util.computeImplicitCoin' , ( ) => {
5
6
let rewardAccount : Cardano . RewardAccount ;
@@ -61,18 +62,19 @@ describe('Cardano.util.computeImplicitCoin', () => {
61
62
62
63
it ( 'sums registrations for deposit, withdrawals and deregistrations for input' , ( ) => {
63
64
const protocolParameters = { dRepDeposit : 5 , poolDeposit : 3 , stakeKeyDeposit : 2 } as Cardano . ProtocolParameters ;
65
+ const poolId = Cardano . PoolId . fromKeyHash ( Ed25519KeyHashHex ( Cardano . RewardAccount . toHash ( rewardAccount ) ) ) ;
64
66
const certificates : Cardano . Certificate [ ] = [
65
67
{ __typename : Cardano . CertificateType . StakeRegistration , stakeCredential } ,
66
68
{ __typename : Cardano . CertificateType . StakeDeregistration , stakeCredential } ,
67
69
{ __typename : Cardano . CertificateType . StakeRegistration , stakeCredential } ,
68
70
{
69
71
__typename : Cardano . CertificateType . PoolRetirement ,
70
72
epoch : Cardano . EpochNo ( 500 ) ,
71
- poolId : Cardano . PoolId ( 'pool1zuevzm3xlrhmwjw87ec38mzs02tlkwec9wxpgafcaykmwg7efhh' )
73
+ poolId
72
74
} ,
73
75
{
74
76
__typename : Cardano . CertificateType . StakeDelegation ,
75
- poolId : Cardano . PoolId ( 'pool1zuevzm3xlrhmwjw87ec38mzs02tlkwec9wxpgafcaykmwg7efhh' ) ,
77
+ poolId,
76
78
stakeCredential
77
79
} ,
78
80
{
@@ -88,7 +90,7 @@ describe('Cardano.util.computeImplicitCoin', () => {
88
90
}
89
91
] ;
90
92
const withdrawals : Cardano . Withdrawal [ ] = [ { quantity : 5n , stakeAddress : rewardAccount } ] ;
91
- const coin = Cardano . util . computeImplicitCoin ( protocolParameters , { certificates, withdrawals } ) ;
93
+ const coin = Cardano . util . computeImplicitCoin ( protocolParameters , { certificates, withdrawals } , [ rewardAccount ] ) ;
92
94
expect ( coin . deposit ) . toBe ( 2n + 2n + 7n ) ;
93
95
expect ( coin . input ) . toBe ( 2n + 3n + 5n + 7n ) ;
94
96
expect ( coin . withdrawals ) . toBe ( 5n ) ;
@@ -203,6 +205,34 @@ describe('Cardano.util.computeImplicitCoin', () => {
203
205
expect ( coin . withdrawals ) . toBe ( withdrawals [ 0 ] . quantity ) ;
204
206
} ) ;
205
207
208
+ it ( 'sums withdrawals for input for own reward accounts' , ( ) => {
209
+ const protocolParameters = { dRepDeposit : 5 , poolDeposit : 3 , stakeKeyDeposit : 2 } as Cardano . ProtocolParameters ;
210
+ const certificates : Cardano . Certificate [ ] = [ ] ;
211
+ const foreignRewardAccount = Cardano . RewardAccount (
212
+ 'stake_test17rphkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcljw6kf'
213
+ ) ;
214
+ const withdrawals : Cardano . Withdrawal [ ] = [
215
+ { quantity : 15n , stakeAddress : foreignRewardAccount } ,
216
+ { quantity : 5n , stakeAddress : rewardAccount }
217
+ ] ;
218
+ const coin = Cardano . util . computeImplicitCoin ( protocolParameters , { certificates, withdrawals } , [ rewardAccount ] ) ;
219
+ expect ( coin . withdrawals ) . toBe ( 5n ) ;
220
+ } ) ;
221
+
222
+ it ( 'sums all withdrawals for input if there are no reward accounts provided' , ( ) => {
223
+ const protocolParameters = { dRepDeposit : 5 , poolDeposit : 3 , stakeKeyDeposit : 2 } as Cardano . ProtocolParameters ;
224
+ const certificates : Cardano . Certificate [ ] = [ ] ;
225
+ const foreignRewardAccount = Cardano . RewardAccount (
226
+ 'stake_test17rphkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcljw6kf'
227
+ ) ;
228
+ const withdrawals : Cardano . Withdrawal [ ] = [
229
+ { quantity : 15n , stakeAddress : foreignRewardAccount } ,
230
+ { quantity : 5n , stakeAddress : rewardAccount }
231
+ ] ;
232
+ const coin = Cardano . util . computeImplicitCoin ( protocolParameters , { certificates, withdrawals } ) ;
233
+ expect ( coin . withdrawals ) . toBe ( 20n ) ;
234
+ } ) ;
235
+
206
236
it ( 'sums certificates and proposal procedures for deposit' , ( ) => {
207
237
const protocolParameters = { governanceActionDeposit : 4 , stakeKeyDeposit : 2 } as Cardano . ProtocolParameters ;
208
238
const governanceActionDeposit = BigInt ( protocolParameters . governanceActionDeposit ! ) ;
0 commit comments