44import http
55import subprocess
66import os
7- import glob
87import infra .network
98import infra .path
109import infra .proc
1817
1918THIS_DIR = os .path .dirname (__file__ )
2019
20+ MODULE_PREFIX_1 = "/app/"
2121MODULE_PATH_1 = "/app/foo.js"
2222MODULE_RETURN_1 = "Hello world!"
2323MODULE_CONTENT_1 = f"""
@@ -85,7 +85,7 @@ def make_module_set_proposal(path, content, network):
8585def test_module_set_and_remove (network , args ):
8686 primary , _ = network .find_nodes ()
8787
88- LOG .info ("Member makes a module update proposal" )
88+ LOG .info ("Member makes a module set proposal" )
8989 make_module_set_proposal (MODULE_PATH_1 , MODULE_CONTENT_1 , network )
9090
9191 with primary .client (
@@ -110,6 +110,35 @@ def test_module_set_and_remove(network, args):
110110 return network
111111
112112
113+ @reqs .description ("Test prefix-based modules remove" )
114+ def test_modules_remove (network , args ):
115+ primary , _ = network .find_nodes ()
116+
117+ LOG .info ("Member makes a module set proposal" )
118+ make_module_set_proposal (MODULE_PATH_1 , MODULE_CONTENT_1 , network )
119+
120+ with primary .client (
121+ f"member{ network .consortium .get_any_active_member ().member_id } "
122+ ) as c :
123+ r = c .post ("/gov/read" , {"table" : "ccf.modules" , "key" : MODULE_PATH_1 })
124+ assert r .status_code == http .HTTPStatus .OK , r .status_code
125+ assert r .body ["js" ] == MODULE_CONTENT_1 , r .body
126+
127+ LOG .info ("Member makes a prefix-based modules remove proposal" )
128+ proposal_body , _ = ccf .proposal_generator .remove_modules (MODULE_PREFIX_1 )
129+ proposal = network .consortium .get_any_active_member ().propose (
130+ primary , proposal_body
131+ )
132+ network .consortium .vote_using_majority (primary , proposal )
133+
134+ with primary .client (
135+ f"member{ network .consortium .get_any_active_member ().member_id } "
136+ ) as c :
137+ r = c .post ("/gov/read" , {"table" : "ccf.modules" , "key" : MODULE_PATH_1 })
138+ assert r .status_code == http .HTTPStatus .BAD_REQUEST , r .status_code
139+ return network
140+
141+
113142@reqs .description ("Test module import" )
114143def test_module_import (network , args ):
115144 primary , _ = network .find_nodes ()
@@ -132,7 +161,7 @@ def test_module_import(network, args):
132161 return network
133162
134163
135- @reqs .description ("Test Node.js/npm app" )
164+ @reqs .description ("Test Node.js/npm app with prefix-based modules update " )
136165def test_npm_app (network , args ):
137166 primary , _ = network .find_nodes ()
138167
@@ -142,15 +171,16 @@ def test_npm_app(network, args):
142171 subprocess .run (["npm" , "run" , "build" ], cwd = app_dir , check = True )
143172
144173 LOG .info ("Deploying npm app modules" )
145- kv_prefix = "/my-npm-app"
174+ module_name_prefix = "/my-npm-app/ "
146175 dist_dir = os .path .join (app_dir , "dist" )
147- for module_path in glob .glob (os .path .join (dist_dir , "**" , "*.js" ), recursive = True ):
148- module_name = os .path .join (kv_prefix , os .path .relpath (module_path , dist_dir ))
149- proposal_body , _ = ccf .proposal_generator .set_module (module_name , module_path )
150- proposal = network .consortium .get_any_active_member ().propose (
151- primary , proposal_body
152- )
153- network .consortium .vote_using_majority (primary , proposal )
176+
177+ proposal_body , _ = ccf .proposal_generator .update_modules (
178+ module_name_prefix , dist_dir
179+ )
180+ proposal = network .consortium .get_any_active_member ().propose (
181+ primary , proposal_body
182+ )
183+ network .consortium .vote_using_majority (primary , proposal )
154184
155185 LOG .info ("Deploying endpoint script" )
156186 with tempfile .NamedTemporaryFile ("w" ) as f :
@@ -186,6 +216,7 @@ def run(args):
186216 ) as network :
187217 network .start_and_join (args )
188218 network = test_module_set_and_remove (network , args )
219+ network = test_modules_remove (network , args )
189220 network = test_module_import (network , args )
190221 network = test_npm_app (network , args )
191222
0 commit comments