| 638 | } |
| 639 | } |
| 640 | static void exactBudget_test(void) { |
| 641 | /* Core Simplicity program with a cost that is exactly 410000 milliWU */ |
| 642 | const unsigned char program[] = { |
| 643 | 0xe0, 0x09, 0x40, 0x81, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x81, 0x02, |
| 644 | 0x05, 0xb4, 0x6d, 0xa0, 0x80 |
| 645 | }; |
| 646 | const ubounded expectedCost = 410; /* in WU */ |
| 647 | |
| 648 | printf("Test exactBudget\n"); |
| 649 | |
| 650 | dag_node* dag; |
| 651 | type* type_dag; |
| 652 | combinator_counters census; |
| 653 | int_fast32_t len; |
| 654 | simplicity_err error, expected; |
| 655 | sha256_midstate ihr; |
| 656 | { |
| 657 | bitstream stream = initializeBitstream(program, sizeof(program)); |
| 658 | len = simplicity_decodeMallocDag(&dag, simplicity_elements_decodeJet, &census, &stream); |
| 659 | simplicity_assert(dag); |
| 660 | simplicity_assert(0 < len); |
| 661 | error = simplicity_closeBitstream(&stream); |
| 662 | simplicity_assert(IS_OK(error)); |
| 663 | } |
| 664 | error = simplicity_mallocTypeInference(&type_dag, simplicity_elements_mallocBoundVars, dag, (uint_fast32_t)len, &census); |
| 665 | simplicity_assert(IS_OK(error)); |
| 666 | simplicity_assert(type_dag); |
| 667 | simplicity_assert(!dag[len-1].sourceType); |
| 668 | simplicity_assert(!dag[len-1].targetType); |
| 669 | { |
| 670 | bitstream stream = initializeBitstream(NULL, 0); |
| 671 | error = simplicity_fillWitnessData(dag, type_dag, (uint_fast32_t)len, &stream); |
| 672 | simplicity_assert(IS_OK(error)); |
| 673 | } |
| 674 | error = simplicity_verifyNoDuplicateIdentityHashes(&ihr, dag, type_dag, (uint_fast32_t)len); |
| 675 | simplicity_assert(IS_OK(error)); |
| 676 | { |
| 677 | ubounded cellsBound, UWORDBound, frameBound, costBound; |
| 678 | error = simplicity_analyseBounds(&cellsBound, &UWORDBound, &frameBound, &costBound, UBOUNDED_MAX, 0, UBOUNDED_MAX, dag, type_dag, (uint_fast32_t)len); |
| 679 | simplicity_assert(IS_OK(error)); |
| 680 | simplicity_assert(1000*expectedCost == costBound); |
| 681 | } |
| 682 | error = evalTCOProgram(dag, type_dag, (uint_fast32_t)len, expectedCost, &expectedCost, NULL); |
| 683 | expected = SIMPLICITY_ERR_OVERWEIGHT; |
| 684 | if (expected == error) { |
| 685 | successes++; |
| 686 | } else { |
| 687 | failures++; |
| 688 | printf("Expected %d from evaluation, but got %d instead.\n", expected, error); |
| 689 | } |
| 690 | error = evalTCOProgram(dag, type_dag, (uint_fast32_t)len, expectedCost-1, &(ubounded){expectedCost-1}, NULL); |
| 691 | expected = SIMPLICITY_ERR_EXEC_BUDGET; |
| 692 | if (expected == error) { |
| 693 | successes++; |
| 694 | } else { |
| 695 | failures++; |
| 696 | printf("Expected %d from evaluation, but got %d instead.\n", expected, error); |
| 697 | } |
no test coverage detected