owned this note
owned this note
Published
Linked with GitHub
# Entangle Test Note
### IOTA transaction process
1. Constructing the bundle and signing of Inputs
2. Tip selection
3. Proof of Work
private key = seed + key index
https://hackmd.io/GlI317NdQ1CYIiCg4fjsIw?view
http://blog.lekkertech.net/blog/2018/03/07/iota-signatures/
### Entangled Unit Test Note
https://hackmd.io/H1zRINMLTuWYzrIK-T9MRQ
### Testing process
**The testing is done by implementing GTest with CMake**
#### needed tool on ubuntu
* CMake
* xsltproc (needed in Keccak toolchain)
* maven
#### Setup the testing environment manually:
for both iota ==public net== and ==testnet== have the following drawbacks:
* Possible network congestions
* Nodes are subject to changes (not available anymore, different API, ...)
* Funds on an address are subject to changes
therefore, using ==snapshot== instead
the [github link of snapshot](https://github.com/schierlm/private-iota-testnet)
maybe we have design a tool for automatically assigning the IOTA for each testing address or develop a sricpt to automatically setup evertthing
there are a few steps to setup the environment
1. Generate a snapshot
2. Run IRI
* Download iotaledger/iri:
* The followings are the steps to setup iri
```
$ git clone https://github.com/iotaledger/iri
$ cd iri
$ mvn clean compile
$ mvn package
```
And this will create a target directory in which you will find the executable jar file that you can use.
* ~~.Checkout the dev branch.~~
* Copy the iri_config/Snapshot.txt file generated previously into src/main/resources
* Copy the iri_config/iri.ini file at the root of the iri repository
* the directory of ==iri_config/== in the above two steps is ==/iota.lib.cpp/test/testnet/iri_config==
* the directory of ==src/main/resources== is in ==/iri== in private-iota-testnet, so the complete directiry is ==/iri/src/main/resources==
* Build mvn clean compile && mvn package
* ~~.Run java -jar target/iri-1.4.2.4.jar --testnet --testnet-no-coo-validation --apshot=src/main/resources/Snapshot.txt -p 14265 --mwm 1 -c iri.ini.~~
* The current version of iri is 1.5.1, so using the following cmd instead
* use this cmd in /private-iota-testnet
```
java -jar target/iri-1.5.1.jar --testnet --testnet-no-coo-validation --snapshot=src/main/resources/Snapshot.txt -p 14265 --mwm 1 -c iri.ini
```
4. Run a coordinator to generate a milestone
5. Attach the addresses
6. Add additional data
7. Update the TestNet DB
#### Faster way to setup environment:
##### 1. To compile & package iri
```
$ git clone https://github.com/iotaledger/iri
$ cd iri
$ mvn clean compile
$ mvn package
```
checkout if install iri successfully, for iri.1.5.1
```
java -jar iri.1.5.1.jar -p 14265
```
###### 2. To install iota.lib.cpp
```
git clone --recursive git@github.com:thibault-martinez/iota.lib.cpp.git
cd iota.lib.cpp
mkdir build
cd build
cmake ..
make
```
Then run the unit test
```
cd iota.lib.cpp
./run_build.sh
```
Then you will see the result
```
The following tests FAILED:
1 - extended_get_bundle_test (Failed)
2 - extended_bundles_from_addresses_test (Failed)
3 - extended_get_balances_and_format_test (Failed)
4 - extended_initiate_transfer_test (Failed)
5 - extended_get_account_data_test (Failed)
6 - extended_replay_bundle_test (Failed)
7 - extended_get_inputs_test (Failed)
8 - extended_send_transfer_test (Failed)
9 - extended_get_new_addresses_test (SEGFAULT)
10 - extended_add_remainder_test (Failed)
11 - extended_broadcast_and_store_test (Failed)
12 - extended_get_transfers_test (Failed)
13 - extended_find_transactions_test (Failed)
14 - extended_traverse_bundle_test (Failed)
15 - extended_find_transaction_objects_test (Failed)
16 - extended_find_transaction_objects_by_bundle_test (Failed)
17 - extended_prepare_transfers_test (Failed)
18 - extended_get_transactions_objects_test (Failed)
19 - extended_is_reattachable_test (Failed)
20 - extended_is_promotable_test (Failed)
21 - extended_get_latest_inclusion_test (Failed)
22 - extended_send_trytes_test (Failed)
40 - core_attach_to_tangle_test (Failed)
41 - core_broadcast_transactions_test (Failed)
43 - core_store_transactions_test (Failed)
44 - core_get_inclusions_states_test (Failed)
45 - core_get_trytes_test (Failed)
46 - core_get_transactions_to_approve_test (Failed)
47 - core_were_addresses_spent_from_test (Failed)
48 - core_find_transactions_test (Failed)
50 - core_get_balances_test (Failed)
51 - core_check_consistency_test (Failed)
88 - crypto_pow_test (Failed)
89 - crypto_multi_signing_test (Failed)
```
This result is normal, even there are so many FAILED tests, since we haven't setup the Snapshot for testing
##### 3. Copy files to assigned directory
* Copy the iota.lib.cpp/test/testnet/iri_config/Snapshot.txt file generated previously into iri/src/main/resources
* Copy the iota.lib.cpp/test/testnet/iri_config/iri.ini file at the root of the iri repository
##### 4. Run the testnet
run the srcipt iota.lib.cpp/test/testnet/script/iri_setup.sh
if there is no error, then you can run iota.lib.cpp/run_build.sh correctlly
However, if the following error showed, then going to the step 5
```
cp: cannot stat './iri_config/Snapshot.txt': No such file or directory
cp: cannot stat './iri_config/iri.ini': No such file or directory
```
##### 5. Fix failing copy error
* ==LIBRARY_PATH== is the path to your ==iota.lib.cpp== repository
* ==IRI_PATH== is the path to the ==iri== repository
```
cd IRI_PATH
rm -rf testnetdb*
cp -r LIBRARY_PATH/test/testnet/testnetdb .
cp LIBRARY_PATH/test/testnet/iri_config/Snapshot.txt src/main/resources
cp LIBRARY_PATH/test/testnet/iri_config/iri.ini .
```
then rebuild iri
```
cd iri
mvn clean compile && mvn package
```
After the above steps the testnet can be built successfully, and there are no error in the test
#### -jar
-jar filename
```
Executes a program encapsulated in a JAR file. The filename argument is the name of a JAR file with a manifest that contains a
line in the form Main-Class:classname that defines the class with the public static void main(String[] args) method that serves as your application's starting point. When you use the -jar option, the specified JAR file is the source of all user classes, and other class path settings are ignored. For more information about JAR files, see the following resources:
· jar(1)
· The Java Archive (JAR) Files guide at
http://docs.oracle.com/javase/8/docs/technotes/guides/jar/index.html
· Lesson: Packaging Programs in JAR Files at
http://docs.oracle.com/javase/tutorial/deployment/jar/index.html
```
### googleTest
#### googleTest tutorial
https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/
#### googleTest official github
https://github.com/google/googletest
#### TEST()
TEST(test case, current test)
- test case: the logically-related tests should be in the same test case
- current test: the name of this TEST() gonna to test
The following two TEST() are in the same test case
```clike
// Tests factorial of 0.
TEST(FactorialTest, HandlesZeroInput) {
EXPECT_EQ(Factorial(0), 1);
}
// Tests factorial of positive numbers.
TEST(FactorialTest, HandlesPositiveInput) {
EXPECT_EQ(Factorial(1), 1);
EXPECT_EQ(Factorial(2), 2);
EXPECT_EQ(Factorial(3), 6);
EXPECT_EQ(Factorial(8), 40320);
}
```
### cmake
[CMake official tutorial](https://cmake.org/cmake-tutorial/)
[CMake building tutorial](https://zh.wikibooks.org/zh-tw/CMake_入門/建置與連結程式庫)
[brief CMake tutorial](https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html)
https://www.kancloud.cn/itfanr/cmake-practice/82985
#### find_package [link](https://cmake.org/cmake/help/v3.0/command/find_package.html)
Load settings for an external project.
The REQUIRED option stops processing with an error message if the package cannot be found.
#### GTEST_INCLUDE_DIRS
https://cmake.org/cmake/help/v3.0/module/FindGTest.html
#### set() [link](https://cmake.org/cmake/help/v3.0/command/set.html)
Set a CMake, cache or environment variable to a given value.
#### run_build.sh in iota.lib.cpp
``` clike
1 #!/bin/bash
...
...
... # omit some copyright comment
28 BLUE='\033[0;34m'
29 GREEN='\033[0;32m'
30 RED='\033[0;31m'
31 NORMAL='\033[0m'
32
33 info() { echo -e "${BLUE}$1${NORMAL}"; }
34 success() { echo -e "${GREEN}$1${NORMAL}"; }
35 fail() { >&2 echo -e "${RED}$1${NORMAL}"; }
36
37 ############################
38 info "Building project..." #
39 ############################
40 mkdir -p buil # no error if exixting, make parent dir as needed
41 cd build
42 cmake -DBUILD_TESTS=1 ..
43 make -j4
44 if [ $? -ne 0 ]; then
45 fail "Error : compilation failed !"
46 exit 1
47 fi
48
49 #########################
50 info "Running tests..." #
51 #########################
52 GTEST_COLOR=1 ctest -VV --test-command
53 if [ $? -ne 0 ]; then
54 fail "Error : tests failed !"
55 exit 1
56 fi
57
58 success "Everything is ok !"
```
1. cmake -D <var>:<type>=<value>, -D <var>=<value>
When cmake is first run in an empty build tree, it creates a
CMakeCache.txt file and populates it with customizable settings
for the project. This option may be used to specify a setting
that takes priority over the project's default value. The
option may be repeated for as many cache entries as desired.
If the :<type> portion is given it must be one of the types
specified by the set() command documentation for its CACHE sig‐
nature. If the :<type> portion is omitted the entry will be
created with no type if it does not exist with a type already.
If a command in the project sets the type to PATH or FILEPATH
then the <value> will be converted to an absolute path.
This option may also be given as a single argument:
-D<var>:<type>=<value> or -D<var>=<value>.
2. -j [jobs], --jobs[=jobs]
Specifies the number of jobs (commands) to run simultaneously. If
there is more than one -j option, the last one is effective. If
the -j option is given without an argument, make will not limit
the number of jobs that can run simultaneously.
3. -ne [link](http://linux.vbird.org/linux_basic/0340bashshell-scripts.php#rule)
-ne is for two values are not equal
4. $? [link](http://linux.vbird.org/linux_basic/0320bash.php)
回船上一個指令的回傳值,成功為0 ,非0 代表失敗
2. ctest -VV,--extra-verbose
Enable more verbose output from tests.
Test output is normally suppressed and only summary information
is displayed. This option will show even more test output.
2.
### scirpt
#### if statement
if [ 條件判斷式 ]; then
當條件判斷式成立時,可以進行的指令工作內容;
fi <==將 if 反過來寫,就成為 fi 啦!結束 if 之意!
### make:
#### $(MAKE)
嵌套执行make
在一些大的工程中,我们会把我们不同模块或是不同功能的源文件放在不同的目录中,我们可以在每个目录中都书写一个该目录的Makefile,这有利于让我们的Makefile变得更加地简洁,而不至于把所有的东西全部写在一个Makefile中,这样会很难维护我们的Makefile,这个技术对于我们模块编译和分段编译有着非常大的好处。
例如,我们有一个子目录叫subdir,这个目录下有个Makefile文件,来指明了这个目录下文件的编译规则。那么我们总控的Makefile可以这样书写:
subsystem:
cd subdir && $(MAKE)
其等价于:
subsystem:
$ (MAKE) -C subdir
定义$(MAKE)宏变量的意思是,也许我们的make需要一些参数,所以定义成一个变量比较利于维护。这两个例子的意思都是先进入“subdir”目录,然后执行make命令。
我们把这个Makefile叫做“总控Makefile”,总控Makefile的变量可以传递到下级的Makefile中(如果你显示的声明),但是不会覆盖下层的Makefile中所定义的变量,除非指定了“-e”参数。