@@ -23,6 +23,7 @@ import (
23
23
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
24
24
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
25
25
"github.com/nspcc-dev/neo-go/pkg/util"
26
+ "github.com/nspcc-dev/neo-go/pkg/vm"
26
27
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
27
28
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
28
29
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
@@ -346,6 +347,9 @@ func getTestContractState(bc *Blockchain) (*state.Contract, *state.Contract) {
346
347
emit .Opcodes (w .BinWriter , opcode .CALLT , 1 , 0 , opcode .RET )
347
348
callT2Off := w .Len ()
348
349
emit .Opcodes (w .BinWriter , opcode .CALLT , 0 , 0 , opcode .RET )
350
+ burnGasOff := w .Len ()
351
+ emit .Syscall (w .BinWriter , interopnames .SystemRuntimeBurnGas )
352
+ emit .Opcodes (w .BinWriter , opcode .RET )
349
353
350
354
script := w .Bytes ()
351
355
h := hash .Hash160 (script )
@@ -506,6 +510,14 @@ func getTestContractState(bc *Blockchain) (*state.Contract, *state.Contract) {
506
510
Offset : callT2Off ,
507
511
ReturnType : smartcontract .IntegerType ,
508
512
},
513
+ {
514
+ Name : "burnGas" ,
515
+ Offset : burnGasOff ,
516
+ Parameters : []manifest.Parameter {
517
+ manifest .NewParameter ("amount" , smartcontract .IntegerType ),
518
+ },
519
+ ReturnType : smartcontract .VoidType ,
520
+ },
509
521
}
510
522
m .Permissions = make ([]manifest.Permission , 2 )
511
523
m .Permissions [0 ].Contract .Type = manifest .PermissionHash
@@ -941,3 +953,37 @@ func TestLoadToken(t *testing.T) {
941
953
checkFAULTState (t , aer )
942
954
})
943
955
}
956
+
957
+ func TestRuntimeBurnGas (t * testing.T ) {
958
+ bc := newTestChain (t )
959
+
960
+ cs , _ := getTestContractState (bc )
961
+ require .NoError (t , bc .contracts .Management .PutContractState (bc .dao , cs ))
962
+
963
+ const sysFee = 2_000000
964
+
965
+ t .Run ("good" , func (t * testing.T ) {
966
+ aer , err := invokeContractMethod (bc , sysFee , cs .Hash , "burnGas" , int64 (1 ))
967
+ require .NoError (t , err )
968
+ require .Equal (t , vm .HaltState , aer .VMState )
969
+
970
+ t .Run ("gas limit exceeded" , func (t * testing.T ) {
971
+ aer , err = invokeContractMethod (bc , aer .GasConsumed , cs .Hash , "burnGas" , int64 (2 ))
972
+ require .NoError (t , err )
973
+ require .Equal (t , vm .FaultState , aer .VMState )
974
+ })
975
+ })
976
+ t .Run ("too big integer" , func (t * testing.T ) {
977
+ gas := big .NewInt (math .MaxInt64 )
978
+ gas .Add (gas , big .NewInt (1 ))
979
+
980
+ aer , err := invokeContractMethod (bc , sysFee , cs .Hash , "burnGas" , gas )
981
+ require .NoError (t , err )
982
+ checkFAULTState (t , aer )
983
+ })
984
+ t .Run ("zero GAS" , func (t * testing.T ) {
985
+ aer , err := invokeContractMethod (bc , sysFee , cs .Hash , "burnGas" , int64 (0 ))
986
+ require .NoError (t , err )
987
+ checkFAULTState (t , aer )
988
+ })
989
+ }
0 commit comments