-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename modules, move generic functions to upstream dependencies.
- Loading branch information
Showing
10 changed files
with
154 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//// This Source Code Form is subject to the terms of the Mozilla Public | ||
//// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
//// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
/// Insert an element in a list at the given position. | ||
pub fn insert(self: List<a>, ix: Int, elem: a) -> List<a> { | ||
when self is { | ||
[] -> | ||
[elem] | ||
[head, ..tail] -> | ||
if ix == 0 { | ||
[elem, head, ..tail] | ||
} else { | ||
[head, ..insert(tail, ix - 1, elem)] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//// This Source Code Form is subject to the terms of the Mozilla Public | ||
//// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
//// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
use aiken/collection/list/extra.{insert} | ||
|
||
test insert_examples() { | ||
and { | ||
(insert([], 0, elem: 0) == [0])?, | ||
(insert([], 2, elem: 0) == [0])?, | ||
(insert([1, 2], 0, elem: 0) == [0, 1, 2])?, | ||
(insert([1, 2], 2, elem: 0) == [1, 2, 0])?, | ||
(insert([1, 2], -1, elem: 0) == [1, 2, 0])?, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//// This Source Code Form is subject to the terms of the Mozilla Public | ||
//// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
//// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
use aiken/collection/list | ||
use aiken/fuzz.{ | ||
and_then, both, bytearray_between, constant, either, int, int_between, | ||
label_when, list_between, map, | ||
} | ||
use sundae/multisig.{ | ||
After, AllOf, AnyOf, AtLeast, Before, MultisigScript, Script, Signature, | ||
} | ||
use zhuli/state.{ | ||
BlockProduction, DelegateKind, Governance, into_asset_name, match_prefix, | ||
} | ||
|
||
test prop_prefix( | ||
(kind, script) via both(any_delegate_kind(), any_multisig_script()), | ||
) { | ||
label_when(kind == Governance, @"Governance", @"BlockProduction") | ||
match_prefix(kind, into_asset_name(kind, script)) | ||
} | ||
|
||
fn any_delegate_kind() -> Fuzzer<DelegateKind> { | ||
either(constant(BlockProduction), constant(Governance)) | ||
} | ||
|
||
fn any_multisig_script() -> Fuzzer<MultisigScript> { | ||
any_multisig_script_at_depth(3) | ||
} | ||
|
||
fn any_multisig_script_at_depth(depth: Int) -> Fuzzer<MultisigScript> { | ||
if depth <= 0 { | ||
map(bytearray_between(28, 28), Signature) | ||
} else { | ||
let variant <- and_then(int_between(0, 7)) | ||
if variant < 4 { | ||
if variant < 2 { | ||
if variant < 1 { | ||
map(bytearray_between(28, 28), Signature) | ||
} else { | ||
map( | ||
list_between(any_multisig_script_at_depth(depth - 1), 0, depth), | ||
AllOf, | ||
) | ||
} | ||
} else { | ||
if variant == 2 { | ||
map( | ||
list_between(any_multisig_script_at_depth(depth - 1), 0, depth), | ||
AnyOf, | ||
) | ||
} else { | ||
let scripts <- | ||
and_then( | ||
list_between(any_multisig_script_at_depth(depth - 1), 0, depth), | ||
) | ||
let required <- map(int_between(0, list.length(scripts))) | ||
AtLeast { required, scripts } | ||
} | ||
} | ||
} else { | ||
if variant < 6 { | ||
if variant < 5 { | ||
map(int(), Before) | ||
} else { | ||
map(int(), After) | ||
} | ||
} else { | ||
map(bytearray_between(28, 28), Script) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.