@@ -1689,6 +1689,185 @@ func Test_Direct_ManagedGetBackTransfers(t *testing.T) {
16891689 assert .Nil (t , err )
16901690}
16911691
1692+ func Test_MultipleCalls_ManagedGetBackTransfers (t * testing.T ) {
1693+ testConfig := makeTestConfig ()
1694+ egldBalance := big .NewInt (10 )
1695+ egldTransfer := big .NewInt (1 )
1696+ initialESDTTokenBalance := uint64 (100 )
1697+ testConfig .ESDTTokensToTransfer = 5
1698+ callsNumber := 2
1699+
1700+ _ , err := test .BuildMockInstanceCallTest (t ).
1701+ WithContracts (
1702+ test .CreateMockContract (test .ParentAddress ).
1703+ WithBalance (testConfig .ParentBalance ).
1704+ WithConfig (testConfig ).
1705+ WithMethods (func (parentInstance * mock.InstanceMock , config interface {}) {
1706+ parentInstance .AddMockMethod ("callChild" , func () * mock.InstanceMock {
1707+ host := parentInstance .Host
1708+
1709+ for i := 0 ; i < callsNumber ; i ++ {
1710+ input := test .DefaultTestContractCallInput ()
1711+ input .GasProvided = testConfig .GasProvidedToChild
1712+ input .CallerAddr = test .ParentAddress
1713+ input .RecipientAddr = test .ChildAddress
1714+ input .Function = "childFunction"
1715+ returnValue := contracts .ExecuteOnDestContextInMockContracts (host , input )
1716+ assert .Equal (t , int32 (0 ), returnValue )
1717+ }
1718+
1719+ managedTypes := host .ManagedTypes ()
1720+ esdtTransfers , egld := managedTypes .GetBackTransfers ()
1721+ assert .Equal (t , callsNumber , len (esdtTransfers ))
1722+ for i := 0 ; i < callsNumber ; i ++ {
1723+ assert .Equal (t , test .ESDTTestTokenName , esdtTransfers [i ].ESDTTokenName )
1724+ assert .Equal (t , big .NewInt (0 ).SetUint64 (testConfig .ESDTTokensToTransfer ), esdtTransfers [i ].ESDTValue )
1725+ }
1726+ assert .Equal (t , big .NewInt (egldTransfer .Int64 ()* int64 (callsNumber )), egld )
1727+ return parentInstance
1728+ })
1729+ }),
1730+ test .CreateMockContract (test .ChildAddress ).
1731+ WithBalance (testConfig .ChildBalance ).
1732+ WithConfig (testConfig ).
1733+ WithMethods (func (parentInstance * mock.InstanceMock , config interface {}) {
1734+ parentInstance .AddMockMethod ("childFunction" , func () * mock.InstanceMock {
1735+ host := parentInstance .Host
1736+
1737+ valueBytes := egldTransfer .Bytes ()
1738+ err := host .Output ().Transfer (
1739+ test .ParentAddress ,
1740+ test .ChildAddress , 0 , 0 , big .NewInt (0 ).SetBytes (valueBytes ), nil , []byte {}, vm .DirectCall )
1741+ assert .Nil (t , err )
1742+
1743+ transfer := & vmcommon.ESDTTransfer {
1744+ ESDTValue : big .NewInt (int64 (testConfig .ESDTTokensToTransfer )),
1745+ ESDTTokenName : test .ESDTTestTokenName ,
1746+ ESDTTokenType : 0 ,
1747+ ESDTTokenNonce : 0 ,
1748+ }
1749+
1750+ ret := vmhooks .TransferESDTNFTExecuteWithTypedArgs (
1751+ host ,
1752+ test .ParentAddress ,
1753+ []* vmcommon.ESDTTransfer {transfer },
1754+ int64 (testConfig .GasProvidedToChild ),
1755+ nil ,
1756+ nil )
1757+ assert .Equal (t , ret , int32 (0 ))
1758+
1759+ return parentInstance
1760+ })
1761+ }),
1762+ ).
1763+ WithSetup (func (host vmhost.VMHost , world * worldmock.MockWorld ) {
1764+ childAccount := world .AcctMap .GetAccount (test .ChildAddress )
1765+ childAccount .SetBalance (egldBalance .Int64 ())
1766+ _ = childAccount .SetTokenBalanceUint64 (test .ESDTTestTokenName , 0 , initialESDTTokenBalance )
1767+ createMockBuiltinFunctions (t , host , world )
1768+ setZeroCodeCosts (host )
1769+ }).
1770+ WithInput (test .CreateTestContractCallInputBuilder ().
1771+ WithRecipientAddr (test .ParentAddress ).
1772+ WithGasProvided (testConfig .GasProvided ).
1773+ WithFunction ("callChild" ).
1774+ Build ()).
1775+ AndAssertResults (func (world * worldmock.MockWorld , verify * test.VMOutputVerifier ) {
1776+ verify .
1777+ Ok ()
1778+ })
1779+ assert .Nil (t , err )
1780+ }
1781+
1782+ func Test_MultipleCalls_MultipleReads_ManagedGetBackTransfers (t * testing.T ) {
1783+ testConfig := makeTestConfig ()
1784+ egldBalance := big .NewInt (10 )
1785+ egldTransfer := big .NewInt (1 )
1786+ initialESDTTokenBalance := uint64 (100 )
1787+ testConfig .ESDTTokensToTransfer = 5
1788+ callsNumber := 2
1789+
1790+ _ , err := test .BuildMockInstanceCallTest (t ).
1791+ WithContracts (
1792+ test .CreateMockContract (test .ParentAddress ).
1793+ WithBalance (testConfig .ParentBalance ).
1794+ WithConfig (testConfig ).
1795+ WithMethods (func (parentInstance * mock.InstanceMock , config interface {}) {
1796+ parentInstance .AddMockMethod ("callChild" , func () * mock.InstanceMock {
1797+ host := parentInstance .Host
1798+
1799+ for i := 0 ; i < callsNumber ; i ++ {
1800+ input := test .DefaultTestContractCallInput ()
1801+ input .GasProvided = testConfig .GasProvidedToChild
1802+ input .CallerAddr = test .ParentAddress
1803+ input .RecipientAddr = test .ChildAddress
1804+ input .Function = "childFunction"
1805+ returnValue := contracts .ExecuteOnDestContextInMockContracts (host , input )
1806+ assert .Equal (t , int32 (0 ), returnValue )
1807+
1808+ managedTypes := host .ManagedTypes ()
1809+ esdtTransfers , egld := managedTypes .GetBackTransfers ()
1810+ assert .Equal (t , 1 , len (esdtTransfers ))
1811+ assert .Equal (t , test .ESDTTestTokenName , esdtTransfers [0 ].ESDTTokenName )
1812+ assert .Equal (t , big .NewInt (0 ).SetUint64 (testConfig .ESDTTokensToTransfer ), esdtTransfers [0 ].ESDTValue )
1813+ assert .Equal (t , egldTransfer , egld )
1814+ }
1815+
1816+ return parentInstance
1817+ })
1818+ }),
1819+ test .CreateMockContract (test .ChildAddress ).
1820+ WithBalance (testConfig .ChildBalance ).
1821+ WithConfig (testConfig ).
1822+ WithMethods (func (parentInstance * mock.InstanceMock , config interface {}) {
1823+ parentInstance .AddMockMethod ("childFunction" , func () * mock.InstanceMock {
1824+ host := parentInstance .Host
1825+
1826+ valueBytes := egldTransfer .Bytes ()
1827+ err := host .Output ().Transfer (
1828+ test .ParentAddress ,
1829+ test .ChildAddress , 0 , 0 , big .NewInt (0 ).SetBytes (valueBytes ), nil , []byte {}, vm .DirectCall )
1830+ assert .Nil (t , err )
1831+
1832+ transfer := & vmcommon.ESDTTransfer {
1833+ ESDTValue : big .NewInt (int64 (testConfig .ESDTTokensToTransfer )),
1834+ ESDTTokenName : test .ESDTTestTokenName ,
1835+ ESDTTokenType : 0 ,
1836+ ESDTTokenNonce : 0 ,
1837+ }
1838+
1839+ ret := vmhooks .TransferESDTNFTExecuteWithTypedArgs (
1840+ host ,
1841+ test .ParentAddress ,
1842+ []* vmcommon.ESDTTransfer {transfer },
1843+ int64 (testConfig .GasProvidedToChild ),
1844+ nil ,
1845+ nil )
1846+ assert .Equal (t , ret , int32 (0 ))
1847+
1848+ return parentInstance
1849+ })
1850+ }),
1851+ ).
1852+ WithSetup (func (host vmhost.VMHost , world * worldmock.MockWorld ) {
1853+ childAccount := world .AcctMap .GetAccount (test .ChildAddress )
1854+ childAccount .SetBalance (egldBalance .Int64 ())
1855+ _ = childAccount .SetTokenBalanceUint64 (test .ESDTTestTokenName , 0 , initialESDTTokenBalance )
1856+ createMockBuiltinFunctions (t , host , world )
1857+ setZeroCodeCosts (host )
1858+ }).
1859+ WithInput (test .CreateTestContractCallInputBuilder ().
1860+ WithRecipientAddr (test .ParentAddress ).
1861+ WithGasProvided (testConfig .GasProvided ).
1862+ WithFunction ("callChild" ).
1863+ Build ()).
1864+ AndAssertResults (func (world * worldmock.MockWorld , verify * test.VMOutputVerifier ) {
1865+ verify .
1866+ Ok ()
1867+ })
1868+ assert .Nil (t , err )
1869+ }
1870+
16921871func Test_Async_ManagedGetBackTransfers (t * testing.T ) {
16931872 testConfig := makeTestConfig ()
16941873 initialESDTTokenBalance := uint64 (100 )
0 commit comments