@@ -175,7 +175,7 @@ def fixture_instance_message_payg(
175175 "type" : "superfluid" ,
176176 },
177177 "resources" : {"vcpus" : 1 , "memory" : 2048 , "seconds" : 30 },
178- "requirements" : { "cpu" : { "architecture" : "x86_64" }} ,
178+ "requirements" : None ,
179179 "rootfs" : {
180180 "parent" : {
181181 "ref" : "549ec451d9b099cad112d4aaa2c00ac40fb6729a92ff252ff22eef0b5c3cb613" ,
@@ -259,6 +259,113 @@ def fixture_instance_message_payg(
259259
260260 return pending_message
261261
262+ @pytest .fixture
263+ def fixture_new_instance_message_payg (
264+ session_factory : DbSessionFactory ,
265+ ) -> PendingMessageDb :
266+ content = {
267+ "address" : "0x9319Ad3B7A8E0eE24f2E639c40D8eD124C5520Ba" ,
268+ "allow_amend" : False ,
269+ "variables" : {
270+ "VM_CUSTOM_VARIABLE" : "SOMETHING" ,
271+ "VM_CUSTOM_VARIABLE_2" : "32" ,
272+ },
273+ "environment" : {
274+ "reproducible" : True ,
275+ "internet" : False ,
276+ "aleph_api" : False ,
277+ "shared_cache" : False ,
278+ },
279+ "payment" : {
280+ "chain" : "AVAX" ,
281+ "receiver" : "0xA07B1214bAe0D5ccAA25449C3149c0aC83658874" ,
282+ "type" : "superfluid" ,
283+ },
284+ "resources" : {"vcpus" : 1 , "memory" : 2048 , "seconds" : 30 },
285+ "requirements" : {"node" : {"node_hash" : "dc3d1d194a990b5c54380c3c0439562fefa42f5a46807cba1c500ec3affecf04" }},
286+ "rootfs" : {
287+ "parent" : {
288+ "ref" : "549ec451d9b099cad112d4aaa2c00ac40fb6729a92ff252ff22eef0b5c3cb613" ,
289+ "use_latest" : True ,
290+ },
291+ "persistence" : "host" ,
292+ "name" : "test-rootfs" ,
293+ "size_mib" : 20480 ,
294+ },
295+ "authorized_keys" : [
296+ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGULT6A41Msmw2KEu0R9MvUjhuWNAsbdeZ0DOwYbt4Qt user@example" ,
297+ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH0jqdc5dmt75QhTrWqeHDV9xN8vxbgFyOYs2fuQl7CI" ,
298+ ],
299+ "volumes" : [
300+ {
301+ "comment" : "Python libraries. Read-only since a 'ref' is specified." ,
302+ "mount" : "/opt/venv" ,
303+ "ref" : "5f31b0706f59404fad3d0bff97ef89ddf24da4761608ea0646329362c662ba51" ,
304+ "use_latest" : False ,
305+ },
306+ {
307+ "comment" : "Ephemeral storage, read-write but will not persist after the VM stops" ,
308+ "mount" : "/var/cache" ,
309+ "ephemeral" : True ,
310+ "size_mib" : 5 ,
311+ },
312+ {
313+ "comment" : "Working data persisted on the VM supervisor, not available on other nodes" ,
314+ "mount" : "/var/lib/sqlite" ,
315+ "name" : "sqlite-data" ,
316+ "persistence" : "host" ,
317+ "size_mib" : 10 ,
318+ },
319+ {
320+ "comment" : "Working data persisted on the Aleph network. "
321+ "New VMs will try to use the latest version of this volume, "
322+ "with no guarantee against conflicts" ,
323+ "mount" : "/var/lib/statistics" ,
324+ "name" : "statistics" ,
325+ "persistence" : "store" ,
326+ "size_mib" : 10 ,
327+ },
328+ {
329+ "comment" : "Raw drive to use by a process, do not mount it" ,
330+ "name" : "raw-data" ,
331+ "persistence" : "host" ,
332+ "mount" : "/var/raw" ,
333+ "size_mib" : 10 ,
334+ },
335+ ],
336+ "time" : 1619017773.8950517 ,
337+ }
338+
339+ pending_message = PendingMessageDb (
340+ item_hash = "734a1287a2b7b5be060312ff5b05ad1bcf838950492e3428f2ac6437a1acad26" ,
341+ type = MessageType .instance ,
342+ chain = Chain .ETH ,
343+ sender = "0x9319Ad3B7A8E0eE24f2E639c40D8eD124C5520Ba" ,
344+ signature = None ,
345+ item_type = ItemType .inline ,
346+ item_content = json .dumps (content ),
347+ time = timestamp_to_datetime (1619017773.8950577 ),
348+ channel = None ,
349+ reception_time = timestamp_to_datetime (1619017774 ),
350+ fetched = True ,
351+ check_message = False ,
352+ retries = 0 ,
353+ next_attempt = dt .datetime (2023 , 1 , 1 ),
354+ )
355+ with session_factory () as session :
356+
357+ session .add (pending_message )
358+ session .add (
359+ MessageStatusDb (
360+ item_hash = pending_message .item_hash ,
361+ status = MessageStatus .PENDING ,
362+ reception_time = pending_message .reception_time ,
363+ )
364+ )
365+ session .commit ()
366+
367+ return pending_message
368+
262369
263370@pytest .fixture
264371def user_balance (session_factory : DbSessionFactory ) -> AlephBalanceDb :
@@ -658,7 +765,7 @@ async def test_compare_account_cost_with_cost_function_hold(
658765
659766
660767@pytest .mark .asyncio
661- async def test_compare_account_cost_with_cost_payg_funct (
768+ async def test_compare_account_cost_with_cost_legacy_payg_funct (
662769 session_factory : DbSessionFactory ,
663770 message_processor : PendingMessageProcessor ,
664771 fixture_instance_message_payg : PendingMessageDb ,
@@ -697,6 +804,46 @@ async def test_compare_account_cost_with_cost_payg_funct(
697804 assert cost == Decimal ("0.000015287547777772" )
698805 assert cost == db_cost
699806
807+ @pytest .mark .asyncio
808+ async def test_compare_account_cost_with_cost_payg_funct (
809+ session_factory : DbSessionFactory ,
810+ message_processor : PendingMessageProcessor ,
811+ fixture_new_instance_message_payg : PendingMessageDb ,
812+ fixture_product_prices_aggregate_in_db ,
813+ fixture_settings_aggregate_in_db ,
814+ user_balance : AlephBalanceDb ,
815+ ):
816+ with session_factory () as session :
817+ insert_volume_refs (session , fixture_new_instance_message_payg )
818+ session .commit ()
819+
820+ pipeline = message_processor .make_pipeline ()
821+ # Exhaust the iterator
822+ _ = [message async for message in pipeline ]
823+
824+ assert fixture_new_instance_message_payg .item_content
825+
826+ content = InstanceContent .model_validate_json (
827+ fixture_new_instance_message_payg .item_content
828+ ) # Parse again
829+
830+ with session_factory () as session :
831+ assert content .payment .type == PaymentType .superfluid
832+ cost , details = get_total_and_detailed_costs (
833+ session = session ,
834+ content = content ,
835+ item_hash = fixture_new_instance_message_payg .item_hash ,
836+ )
837+
838+ db_cost , details = get_total_and_detailed_costs_from_db (
839+ session = session ,
840+ content = content ,
841+ item_hash = fixture_new_instance_message_payg .item_hash ,
842+ )
843+
844+ assert cost == Decimal ("0.000015287547777772" )
845+ assert cost == db_cost
846+
700847
701848@pytest .fixture
702849def fixture_instance_message_only_rootfs (
@@ -764,7 +911,6 @@ def fixture_instance_message_only_rootfs(
764911
765912 return pending_message
766913
767-
768914@pytest .mark .asyncio
769915async def test_compare_account_cost_with_cost_function_without_volume (
770916 session_factory : DbSessionFactory ,
0 commit comments