github.com/deroproject/derosuite@v2.1.6-1.0.20200307070847-0f2e589c7a2b+incompatible/cryptonight/cryptonightv7_test.go (about)

     1  // Copyright 2017-2018 DERO Project. All rights reserved.
     2  // Use of this source code in any form is governed by RESEARCH license.
     3  // license can be found in the LICENSE file.
     4  // GPG: 0F39 E425 8C65 3947 702A  8234 08B2 0360 A03A 9DE8
     5  //
     6  //
     7  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
     8  // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     9  // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    10  // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    11  // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    12  // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    13  // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    14  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
    15  // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    16  
    17  package cryptonight
    18  
    19  import "fmt"
    20  import "testing"
    21  import "encoding/hex"
    22  
    23  // test cases from original implementation
    24  func Test_Cryptonightv7_Hash(t *testing.T) {
    25  
    26  	tests := []struct {
    27  		data     string
    28  		expected string
    29  	}{
    30  		{
    31  			data:     "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    32  			expected: "b5a7f63abb94d07d1a6445c36c07c7e8327fe61b1647e391b4c7edae5de57a3d",
    33  		},
    34  		{
    35  			data:     "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    36  			expected: "80563c40ed46575a9e44820d93ee095e2851aa22483fd67837118c6cd951ba61",
    37  		},
    38  		{
    39  			data:     "8519e039172b0d70e5ca7b3383d6b3167315a422747b73f019cf9528f0fde341fd0f2a63030ba6450525cf6de31837669af6f1df8131faf50aaab8d3a7405589",
    40  			expected: "5bb40c5880cef2f739bdb6aaaf16161eaae55530e7b10d7ea996b751a299e949",
    41  		},
    42  		{
    43  			data:     "37a636d7dafdf259b7287eddca2f58099e98619d2f99bdb8969d7b14498102cc065201c8be90bd777323f449848b215d2977c92c4c1c2da36ab46b2e389689ed97c18fec08cd3b03235c5e4c62a37ad88c7b67932495a71090e85dd4020a9300",
    44  			expected: "613e638505ba1fd05f428d5c9f8e08f8165614342dac419adc6a47dce257eb3e",
    45  		},
    46  		{
    47  			data:     "38274c97c45a172cfc97679870422e3a1ab0784960c60514d816271415c306ee3a3ed1a77e31f6a885c3cb",
    48  			expected: "ed082e49dbd5bbe34a3726a0d1dad981146062b39d36d62c71eb1ed8ab49459b",
    49  		},
    50  	}
    51  
    52  	for _, test := range tests {
    53  		data, err := hex.DecodeString(test.data)
    54  		if err != nil {
    55  			t.Fatalf("Could NOT decode test")
    56  		}
    57  
    58  		actual := SlowHashv7(data)
    59  		//t.Logf("cryptonightv7: want: %s, got: %x", test.expected, actual)
    60  		if fmt.Sprintf("%x", actual) != test.expected {
    61  			t.Fatalf("cryptonightv7: want: %s, got: %x", test.expected, actual)
    62  			continue
    63  		}
    64  
    65  	}
    66  
    67  }