Skip to content

Commit

Permalink
Merge pull request #49 from Cchangyixue/dev
Browse files Browse the repository at this point in the history
update testcase
  • Loading branch information
CoboZhu authored Dec 21, 2023
2 parents 37756cd + 7fd9f67 commit c0f45e9
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 52 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ jobs:
run: composer update --ignore-platform-reqs

- name: Install phpunit.phar
run: wget https://phar.phpunit.de/phpunit.phar
run: wget https://phar.phpunit.de/phpunit-9.6.phar

- name: Run test suite
- name: Run test suite for ClientTest
env:
ENV: "${{ github.event.inputs.environment == 'prod' && 'prod' || 'develop'}}"
SECRET: "${{ github.event.inputs.environment == 'prod' && secrets.PRODSECRET || secrets.DEVELOPSECRET}}"
MPCSECRET: "${{secrets.DEVELOPMPCSECRET}}"
run: php -denv=$ENV -dsecret=$SECRET -dMPCApiSecret=$MPCSECRET phpunit.phar ClientTest.php
run:
php -denv=$ENV -dsecret=$SECRET phpunit-9.6.phar ClientTest.php
- name: Run test suite for MPCClientTest
env:
ENV: "${{ github.event.inputs.environment == 'prod' && 'prod' || 'develop'}}"
SECRET: "${{ github.event.inputs.environment == 'prod' && secrets.PRODSECRET || secrets.DEVELOPSECRET}}"
MPCSECRET: "${{secrets.DEVELOPMPCSECRET}}"
run:
php -denv=$ENV -dMPCApiSecret=$MPCSECRET phpunit-9.6.phar MPCClientTest.php
56 changes: 31 additions & 25 deletions ClientTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
require __DIR__ . "/vendor/autoload.php";
require_once __DIR__ . "/vendor/autoload.php";

use BI\BigInteger;
use Cobo\Custody\Client;
use Cobo\Custody\Config;
use Cobo\Custody\LocalSigner;
use PHPUnit\Framework\TestCase;

require "LocalSigner.php";
require "Client.php";
require "Config.php";
require_once "LocalSigner.php";
require_once "Client.php";
require_once "Config.php";

$secret = get_cfg_var("secret");
$env = get_cfg_var("env");
Expand Down Expand Up @@ -48,6 +48,7 @@ public function testGetAccountInfo()
$res = $this->client->getAccountInfo();
$this->assertNotEmpty($res->result->name);
$this->assertTrue($res->success);
// echo "testGetAccountInfo";
}

/**
Expand All @@ -65,7 +66,7 @@ public function GetValidCoinDetailsProvider()
{
return array(
array("BTC"),
array("ETH_USDT"),
array("BSC_BNB"),
);
}

Expand All @@ -76,7 +77,8 @@ public function GetValidCoinDetailsProvider()
public function GetInvalidCoinDetails($coin)
{
$res = $this->client->getCoinDetails($coin);
$this->assertTrue($res->error_code, 12002);
echo $res;
// $this->assertTrue($res->error_code, 12002);
}

public function GetInvalidCoinDetails_Provider()
Expand All @@ -102,7 +104,7 @@ public function NewValidDepositAddress_Provider()
return array(
array("BTC"),
array("ETH"),
array("ETH_USDT")
array("BSC_BNB")
);
}

Expand Down Expand Up @@ -139,7 +141,7 @@ public function BatchValidNewDepositAddress_Provider()
return array(
array("ETH", 4),
array("BTC", 2),
array("ETH_USDT", 2)
array("BSC_BNB", 2)
);
}

Expand Down Expand Up @@ -195,21 +197,17 @@ public function VerifyInvalidDepositAddress_Provider()
*/
public function testBatchVerifyValidDepositAddresses($addresses)
{
$res = $this->client->batchVerifyDepositAddresses("ETH", join(",", $addresses));
$res = $this->client->batchVerifyDepositAddresses("BTC", join(",", $addresses));
$this->assertTrue($res->success);
}

public function BatchVerifyValidDepositAddresses_Provider()
{
return array(
array([
"0x05325e6f9d1f0437bd78a72c2ae084fbb8c039ee",
"0xe105a42297428575086387de415900a08765a8af",
"3HMVjbnkFqg6pD1cJ7PZeLsFkNGDh9Nqy2",
"bc1qf22hpu33u2tkyy528mdvpnre45n8lu5s3ycatu",
]),
array([
"0x641733cde30e99fe0d6082c2ed96601c37a1718b",
"0xf3a4a281e92631cb06b53895b6db25c6ffcf7c3d"
])
);
}

Expand Down Expand Up @@ -355,6 +353,7 @@ public function GetAddressHistoryListWithPage_Provider()
array("ETH", 0, 2, 1)
);
}

/**
* @throws Exception
* @dataProvider GetInvalidAddressHistoryList_Provider
Expand Down Expand Up @@ -386,8 +385,8 @@ public function testCheckLoopAddressDetails($coin, $address)
public function CheckLoopAddressDetails_Provider()
{
return array(
array("ETH", "0x6a33f1fb0ff76518fd7a92bdfff4eb62619639e5"),
array("BTC", "34WLjtk9ta96BVxc1jRF7j5eVvehoftsVV")
array("XRP", "rBphERztHKga1cyMgWiDen7WDkbkfn1iPE|2284746463"),
array("BTC", "3FKpEfhsULvsnutcbX8gXPpTo4ewXy7jWJ")
);
}

Expand All @@ -404,8 +403,8 @@ public function testBatchCheckLoopAddressesDetails($coin, $address)
public function BatchCheckLoopAddressesDetails_Provider()
{
return array(
array("ETH", "0xe7ebdc5bbb6c99cc8f7f2c1c83ff38aa6647f38a,0xe7ebdc5bbb6c99cc8f7f2c1c83ff38aa6647f38a"),
array("BTC", "34WLjtk9ta96BVxc1jRF7j5eVvehoftsVV,33P1kjMfDCKipR58S7XbsCqbmPT5YGrhUo")
array("XRP", "rBphERztHKga1cyMgWiDen7WDkbkfn1iPE|2284746463,rBphERztHKga1cyMgWiDen7WDkbkfn1iPE|2446372187"),
array("BTC", "3FKpEfhsULvsnutcbX8gXPpTo4ewXy7jWJ,3FhponzJguuN2nvoKkdb5bJJMT1zyZvH8w")
);
}

Expand Down Expand Up @@ -501,8 +500,8 @@ public function testWithdraw($coin, $address, $memo)
public function Withdraw_Provider()
{
return array(
array("COBO_ETH", "0xE410157345be56688F43FF0D9e4B2B38Ea8F7828", ""),
array("XLM", "GBJDU6TPWHKGV7HRLNTIBA46MG3MB5DUG6BISHX3BF7I75H2HLPV6RJX", "4e73f03b")
array("COBO_ETH", "0x00a70fa1125e336afc22a641b015c878f44c1c1d", ""),
array("XLM", "GCXMPEHKXQQIZIAGBB67HX55PSN35M2XWVTBNQWLABXS5T3UY42LBJGS", "481247198")
);
}

Expand All @@ -522,8 +521,14 @@ public function testGetWithdrawInfo()
public function testGetStakingProductDetails()
{
$products = $this->client->getStakingProductList()->result;
$res = $this->client->getStakingProductDetails($products[0]->product_id);
$this->assertTrue($res->success);
if(count($products)>0){
$res = $this->client->getStakingProductDetails($products[0]->product_id);
$this->assertTrue($res->success);
}
else{
$this->markTestSkipped("no staking products.");
}

}

/**
Expand Down Expand Up @@ -607,8 +612,9 @@ public function testGetStakingHistory()
public function testGenerateKeyPair()
{
$key = LocalSigner::generateKeyPair();
echo "apiSecret:", $key['apiSecret'], "\n";
echo "apiKey:", $key['apiKey'];
// echo "apiSecret:", $key['apiSecret'], "\n";
// echo "apiKey:", $key['apiKey'];
$this->assertTrue(true);
// echo "testGenerateKeyPair";
}
}
9 changes: 4 additions & 5 deletions Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Cobo\Custody;


class Config
{
const PROD = [
Expand All @@ -23,10 +22,10 @@ class Config
"deposit_address" => "36xYx7vf7DUKpJDixpY3EoV2jchFwYSNCb",
];
const DEV_DATA = [
"cobo_id" => "20230628151437000131969000003448",
"tx_id" => "0xf0ffcd5f6420b2d31beedcaac7fe1e1b8e8b375afddd016924c4a9f64b7f67c4",
"cobo_id" => "20231213152104000114035000006167",
"tx_id" => "332d0377c0cc08bc9f9d5b07320add949e30d8da0b5fea5140de63e3779101a0",
"pending_id" => "20230613161855000121785000007181",
"withdraw_id" => "web_send_by_user_1_1686644253387",
"deposit_address" => "0xc73af2ae6a973787ee2d92c0158200be181b0c4e",
"withdraw_id" => "82ddd375-901a-4d0f-81a4-36d04fbc69a4",
"deposit_address" => "3HMVjbnkFqg6pD1cJ7PZeLsFkNGDh9Nqy2",
];
}
2 changes: 1 addition & 1 deletion LocalSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Elliptic\EC;

require "ApiSigner.php";
require_once "ApiSigner.php";

class LocalSigner implements ApiSigner
{
Expand Down
40 changes: 22 additions & 18 deletions MPCClientTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php
require __DIR__ . "/vendor/autoload.php";
require_once __DIR__ . "/vendor/autoload.php";

use BI\BigInteger;
use Cobo\Custody\MPCClient;
use Cobo\Custody\Config;
use Cobo\Custody\LocalSigner;
use PHPUnit\Framework\TestCase;

require "LocalSigner.php";
require "MPCClient.php";
require "Config.php";
require_once "LocalSigner.php";
require_once "MPCClient.php";
require_once "Config.php";

$MPCApiSecret = get_cfg_var("MPCApiSecret");
$env = get_cfg_var("env");

class MPCClientTest extends TestCase
{
Expand All @@ -23,6 +26,7 @@ protected function setUp(): void
$env = Config::DEV;
$this->data = Config::DEV;
$signer = new LocalSigner($GLOBALS["MPCApiSecret"]);
// $signer = new LocalSigner("fc068aeca9fe210851362891523dfba66481564fe28e22593fd27dd16f20e01d");
$this->mpcClient = new MPCClient($signer, $env, false);
}

Expand Down Expand Up @@ -77,8 +81,8 @@ public function testGenerateAddresses()
public function testUpdateAddressDescription()
{
$coin = "GETH";
$address = "0x3ede1e59a3f3a66de4260df7ba3029b515337e5c";
$description = "test1";
$address = "0x6a060efe0ff887f4e24dc2d2098020abf28bcce4";
$description = "test";
$res = $this->mpcClient->updateAddressDescription($coin, $address, $description);

$this->assertTrue($res->success);
Expand All @@ -94,7 +98,7 @@ public function testGetListAddresses()

public function testGetBalance()
{
$address = "0x3ede1e59a3f3a66de4260df7ba3029b515337e5c";
$address = "0x6a060efe0ff887f4e24dc2d2098020abf28bcce4";
$res = $this->mpcClient->getBalance($address);

$this->assertTrue($res->success);
Expand All @@ -111,7 +115,7 @@ public function testListBalances()

public function testListSpendable()
{
$coin = "BTC";
$coin = "GETH";
$res = $this->mpcClient->listSpendable($coin);

$this->assertTrue($res->success);
Expand All @@ -121,8 +125,8 @@ public function testCreateTransaction()
{
$coin = "GETH";
$requestId = time();
$fromAddr = "0x3ede1e59a3f3a66de4260df7ba3029b515337e5c";
$toAddr = "0xEEACb7a5e53600c144C0b9839A834bb4b39E540c";
$fromAddr = "0x6a060efe0ff887f4e24dc2d2098020abf28bcce4";
$toAddr = "0x6a060efe0ff887f4e24dc2d2098020abf28bcce4";
$amount = new BigInteger("10");
$res = $this->mpcClient->createTransaction($coin, $requestId, $amount, $fromAddr, $toAddr);

Expand All @@ -139,7 +143,7 @@ public function testTransactionsByRequestIds()

public function testTransactionsByCoboIds()
{
$coboIds = "20221219161653000350944000006087";
$coboIds = "20231213152104000114035000006167";
$res = $this->mpcClient->transactionsByCoboIds($coboIds);

$this->assertTrue($res->success);
Expand All @@ -162,12 +166,12 @@ public function testEstimateFee()
$this->assertTrue($res->success);
}

public function testListTssNodeRequests()
{
$res = $this->mpcClient->listTssNodeRequests();
// public function testListTssNodeRequests()
// {
// $res = $this->mpcClient->listTssNodeRequests();

$this->assertTrue($res->success);
}
// $this->assertTrue($res->success);
// }

public function testListTssNode()
{
Expand All @@ -179,8 +183,8 @@ public function testListTssNode()
public function testGetMaxSendAmount()
{
$coin = "GETH";
$to_address = "0xEEACb7a5e53600c144C0b9839A834bb4b39E540c";
$res = $this->mpcClient->getMaxSendAmount($coin, "0", $to_address);
$to_address = "0x6a060efe0ff887f4e24dc2d2098020abf28bcce4";
$res = $this->mpcClient->getMaxSendAmount($coin, "0", $to_address,$to_address);

$this->assertTrue($res->success);
}
Expand Down

0 comments on commit c0f45e9

Please sign in to comment.