11use clap:: Parser ;
2- use parity_scale_codec:: Encode ;
3- use pvq_extension:: { extensions_impl, ExtensionsExecutor , InvokeSource } ;
42use tracing_subscriber:: prelude:: * ;
53
4+ use pvq_test_runner:: TestRunner ;
5+
66#[ derive( Parser , Debug ) ]
77#[ command( version, about) ]
88struct Cli {
@@ -26,63 +26,13 @@ fn main() {
2626 let cli = Cli :: parse ( ) ;
2727
2828 let blob = std:: fs:: read ( & cli. program ) . expect ( "Failed to read program" ) ;
29- let mut executor = ExtensionsExecutor :: < extensions:: Extensions , ( ) > :: new ( InvokeSource :: RuntimeAPI ) ;
30- let mut input_data = Vec :: new ( ) ;
3129 let program_str = cli. program . to_string_lossy ( ) ;
32- if program_str. contains ( "sum-balance" ) {
33- input_data. extend_from_slice ( & 0u32 . encode ( ) ) ;
34- input_data. extend_from_slice ( & vec ! [ [ 0u8 ; 32 ] , [ 1u8 ; 32 ] ] . encode ( ) ) ;
35- } else if program_str. contains ( "total-supply" ) {
36- input_data. extend_from_slice ( & 0u32 . encode ( ) ) ;
37- } else if program_str. contains ( "transparent-call" ) {
38- input_data. extend_from_slice ( & 4071833530116166512u64 . encode ( ) ) ;
39- input_data. extend_from_slice (
40- & ExtensionFungiblesFunctions :: balance {
41- asset : 0 ,
42- who : [ 1u8 ; 32 ] ,
43- }
44- . encode ( ) ,
45- ) ;
46- }
47- tracing:: info!( "Input data: {:?}" , input_data) ;
48- let res = executor. execute_method ( & blob, & input_data, 0 ) . unwrap ( ) ;
49-
50- tracing:: info!( "Result: {:?}" , res) ;
51- }
5230
53- #[ derive( Encode ) ]
54- #[ allow( non_camel_case_types) ]
55- #[ allow( dead_code) ]
56- enum ExtensionFungiblesFunctions {
57- #[ codec( index = 0 ) ]
58- total_supply { asset : u32 } ,
59- #[ codec( index = 1 ) ]
60- balance { asset : u32 , who : [ u8 ; 32 ] } ,
61- }
62-
63- #[ extensions_impl]
64- pub mod extensions {
65- #[ extensions_impl:: impl_struct]
66- pub struct ExtensionsImpl ;
31+ let input_data = TestRunner :: prepare_input_data ( & program_str) ;
32+ tracing:: info!( "Input data: {:?}" , input_data) ;
6733
68- #[ extensions_impl:: extension]
69- impl pvq_extension_core:: extension:: ExtensionCore for ExtensionsImpl {
70- type ExtensionId = u64 ;
71- fn has_extension ( id : Self :: ExtensionId ) -> bool {
72- matches ! ( id, 0 | 1 )
73- }
74- }
34+ let mut runner = TestRunner :: new ( ) ;
35+ let res = runner. execute_program ( & blob, & input_data) . unwrap ( ) ;
7536
76- #[ extensions_impl:: extension]
77- impl pvq_extension_fungibles:: extension:: ExtensionFungibles for ExtensionsImpl {
78- type AssetId = u32 ;
79- type AccountId = [ u8 ; 32 ] ;
80- type Balance = u64 ;
81- fn total_supply ( _asset : Self :: AssetId ) -> Self :: Balance {
82- 100
83- }
84- fn balance ( _asset : Self :: AssetId , _who : Self :: AccountId ) -> Self :: Balance {
85- 100
86- }
87- }
37+ tracing:: info!( "Result: {:?}" , res) ;
8838}
0 commit comments