@@ -290,3 +290,56 @@ func TestMsgCall_Failed(t *testing.T) {
290290 require .Error (t , err )
291291 require .Contains (t , err .Error (), "panic while calling VM" )
292292}
293+
294+ // TestMsgCall_Transfer validates calling the faucet.Transfer function which
295+ // transfers 1ugnot from the realm addres to the caller address.
296+ func TestMsgCall_Transfer (t * testing.T ) {
297+ f := initFixture (t )
298+ ms := keeper .NewMsgServerImpl (& f .keeper )
299+
300+ require .NoError (t , f .keeper .InitGenesis (f .ctx , types.GenesisState {Params : types .DefaultParams ()}))
301+
302+ creatorBytes := f .keeper .GetAuthority ()
303+ creatorStr , err := f .addressCodec .BytesToString (creatorBytes )
304+ require .NoError (t , err )
305+
306+ // Read the faucet package from testdata directory
307+ testdataPath := filepath .Join ("testdata" , "faucet" )
308+ mpkg , err := ReadMemPackageFromDir (testdataPath )
309+ require .NoError (t , err )
310+
311+ pkgBz , err := json .Marshal (mpkg )
312+ require .NoError (t , err )
313+
314+ maxDeposit , _ := sdk .ParseCoinsNormalized ("5000stake" )
315+ deposit , _ := sdk .ParseCoinsNormalized ("2115stake" )
316+ send , _ := sdk .ParseCoinsNormalized ("1000stake" )
317+
318+ f .authKeeper .EXPECT ().GetAccount (f .ctx , creatorBytes ).
319+ Return (authtypes .NewBaseAccountWithAddress (creatorBytes )).AnyTimes ()
320+ // Expected SendCoins for the send parameter
321+ pkgAddr := gnolang .DerivePkgCryptoAddr (mpkg .Path ).Bytes ()
322+ f .bankKeeper .EXPECT ().SendCoins (f .ctx , creatorBytes , pkgAddr , send )
323+ // Expected SendCoins for the storage deposit
324+ storageDepositAddr := gnolang .DeriveStorageDepositCryptoAddr (mpkg .Path ).Bytes ()
325+ f .bankKeeper .EXPECT ().SendCoins (f .ctx , creatorBytes , storageDepositAddr , deposit )
326+
327+ addPkgMsg := types .NewMsgAddPackage (creatorStr , send , maxDeposit , pkgBz )
328+
329+ _ , err = ms .AddPackage (f .ctx , addPkgMsg )
330+ require .NoError (t , err )
331+
332+ send , _ = sdk .ParseCoinsNormalized ("2000stake" )
333+
334+ maxDeposit , _ = sdk .ParseCoinsNormalized ("0stake" ) // no storage deposit
335+ deposit , _ = sdk .ParseCoinsNormalized ("0stake" ) // no storage deposit
336+ // Expected SendCoins for the send parameter
337+ f .bankKeeper .EXPECT ().SendCoins (f .ctx , creatorBytes , pkgAddr , send )
338+ // Expected SendCoins for the transfer realm
339+ f .bankKeeper .EXPECT ().SendCoins (f .ctx , pkgAddr , creatorBytes , sdk .NewCoins (sdk .NewInt64Coin ("ugnot" , 1 )))
340+
341+ callMsg := types .NewMsgCall (creatorStr , send , maxDeposit , mpkg .Path , "Transfer" , nil )
342+ resp , err := ms .Call (f .ctx , callMsg )
343+ require .NoError (t , err )
344+ require .NotNil (t , resp )
345+ }
0 commit comments