Get Monero tests to pass on a brand new network

Updates decoy selection with an explicit panic, the removal of a divide 
by 0 (causing tests to fail on new chains), and a minor optimization 
when dealing with a large quantity of locked outputs.

Also increases documentation, acknowledging infinite loops and breakage 
from Monero more.
This commit is contained in:
Luke Parker
2022-05-13 00:05:34 -04:00
parent 3e7598315c
commit bb840da44d
4 changed files with 85 additions and 24 deletions

View File

@@ -1,8 +1,39 @@
use rand::rngs::OsRng;
use curve25519_dalek::constants::ED25519_BASEPOINT_TABLE;
use serde_json::json;
use monero_serai::rpc::{EmptyResponse, RpcError, Rpc};
use monero::{
network::Network,
util::{key::PublicKey, address::Address}
};
pub async fn mine_block(rpc: &Rpc, address: String) -> Result<EmptyResponse, RpcError> {
use monero_serai::{random_scalar, rpc::{EmptyResponse, RpcError, Rpc}};
pub async fn rpc() -> Rpc {
let rpc = Rpc::new("http://127.0.0.1:18081".to_string());
// Only run once
if rpc.get_height().await.unwrap() != 1 {
return rpc;
}
let addr = Address::standard(
Network::Mainnet,
PublicKey { point: (&random_scalar(&mut OsRng) * &ED25519_BASEPOINT_TABLE).compress() },
PublicKey { point: (&random_scalar(&mut OsRng) * &ED25519_BASEPOINT_TABLE).compress() }
).to_string();
// Mine enough blocks decoy selection doesn't fail
for _ in 0 .. 1 {
mine_block(&rpc, &addr).await.unwrap();
}
rpc
}
pub async fn mine_block(rpc: &Rpc, address: &str) -> Result<EmptyResponse, RpcError> {
rpc.rpc_call("json_rpc", Some(json!({
"method": "generateblocks",
"params": {

View File

@@ -7,18 +7,14 @@ use monero::{
util::{key::PublicKey, address::Address}
};
use monero_serai::{
random_scalar,
transaction::{self, SignableTransaction},
rpc::Rpc
};
use monero_serai::{random_scalar, transaction::{self, SignableTransaction}};
mod rpc;
use crate::rpc::mine_block;
use crate::rpc::{rpc, mine_block};
#[tokio::test]
pub async fn send() {
let rpc = Rpc::new("http://127.0.0.1:18081".to_string());
let rpc = rpc().await;
// Generate an address
let view = random_scalar(&mut OsRng);
@@ -40,7 +36,7 @@ pub async fn send() {
for i in 0 .. 2 {
let start = rpc.get_height().await.unwrap();
for _ in 0 .. 7 {
mine_block(&rpc, addr.to_string()).await.unwrap();
mine_block(&rpc, &addr.to_string()).await.unwrap();
}
// Test both a miner output and a normal output

View File

@@ -13,17 +13,17 @@ use monero::{
util::{key::PublicKey, address::Address}
};
use monero_serai::{transaction::{self, SignableTransaction}, rpc::Rpc};
use monero_serai::transaction::{self, SignableTransaction};
mod rpc;
use crate::rpc::mine_block;
use crate::rpc::{rpc, mine_block};
mod frost;
use crate::frost::{THRESHOLD, generate_keys, sign};
#[tokio::test]
pub async fn send_multisig() {
let rpc = Rpc::new("http://127.0.0.1:18081".to_string());
let rpc = rpc().await;
let fee_per_byte = 50000000;
let fee = fee_per_byte * 2000;
@@ -43,7 +43,7 @@ pub async fn send_multisig() {
// Mine blocks to that address
let start = rpc.get_height().await.unwrap();
for _ in 0 .. 7 {
mine_block(&rpc, addr.to_string()).await.unwrap();
mine_block(&rpc, &addr.to_string()).await.unwrap();
}
// Get the input TX