@@ -8,6 +8,7 @@ import { BlockchainNode, ValidatorMetrics } from './helpers/BlockchainNode';
88describe ( 'SFC' , ( ) => {
99 const fixture = async ( ) => {
1010 const [ owner , user ] = await ethers . getSigners ( ) ;
11+ const totalSupply = ethers . parseEther ( '100' ) ;
1112 const sfc = await upgrades . deployProxy ( await ethers . getContractFactory ( 'UnitTestSFC' ) , {
1213 kind : 'uups' ,
1314 initializer : false ,
@@ -24,7 +25,7 @@ describe('SFC', () => {
2425 const evmWriter : IEVMWriter = await ethers . deployContract ( 'StubEvmWriter' ) ;
2526 const initializer : UnitTestNetworkInitializer = await ethers . deployContract ( 'UnitTestNetworkInitializer' ) ;
2627
27- await initializer . initializeAll ( 0 , 0 , sfc , nodeDriverAuth , nodeDriver , evmWriter , owner ) ;
28+ await initializer . initializeAll ( 0 , totalSupply , sfc , nodeDriverAuth , nodeDriver , evmWriter , owner ) ;
2829 const constants : UnitTestConstantsManager = await ethers . getContractAt (
2930 'UnitTestConstantsManager' ,
3031 await sfc . constsAddress ( ) ,
@@ -39,6 +40,7 @@ describe('SFC', () => {
3940 nodeDriver,
4041 nodeDriverAuth,
4142 constants,
43+ totalSupply,
4244 } ;
4345 } ;
4446
@@ -55,6 +57,32 @@ describe('SFC', () => {
5557 ) . to . revertedWithCustomError ( this . sfc , 'TransfersNotAllowed' ) ;
5658 } ) ;
5759
60+ describe ( 'Burn native tokens' , ( ) => {
61+ it ( 'Should revert when no amount sent' , async function ( ) {
62+ await expect ( this . sfc . connect ( this . user ) . burnNativeTokens ( ) ) . to . be . revertedWithCustomError (
63+ this . sfc ,
64+ 'ZeroAmount' ,
65+ ) ;
66+ } ) ;
67+
68+ it ( 'Should revert when amount greater than total supply' , async function ( ) {
69+ await expect (
70+ this . sfc . connect ( this . user ) . burnNativeTokens ( { value : this . totalSupply + 1n } ) ,
71+ ) . to . be . revertedWithCustomError ( this . sfc , 'ValueTooLarge' ) ;
72+ } ) ;
73+
74+ it ( 'Should succeed and burn native tokens' , async function ( ) {
75+ const amount = ethers . parseEther ( '1.5' ) ;
76+ const totalSupply = await this . sfc . totalSupply ( ) ;
77+ const tx = await this . sfc . connect ( this . user ) . burnNativeTokens ( { value : amount } ) ;
78+ await expect ( tx ) . to . emit ( this . sfc , 'BurntNativeTokens' ) . withArgs ( amount ) ;
79+ expect ( await this . sfc . totalSupply ( ) ) . to . equal ( totalSupply - amount ) ;
80+ await expect ( tx ) . to . changeEtherBalance ( this . sfc , 0 ) ;
81+ await expect ( tx ) . to . changeEtherBalance ( this . user , - amount ) ;
82+ await expect ( tx ) . to . changeEtherBalance ( ethers . ZeroAddress , amount ) ;
83+ } ) ;
84+ } ) ;
85+
5886 describe ( 'Genesis validator' , ( ) => {
5987 beforeEach ( async function ( ) {
6088 const validator = ethers . Wallet . createRandom ( ) ;
0 commit comments