github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/test/test_contract_features.js (about)

     1  'use strict';
     2  
     3  var testContract = function() {
     4  
     5  }
     6  
     7  var assert = function(expression, info) {
     8      if (!expression) {
     9          throw info;
    10      }
    11  };
    12  
    13  testContract.prototype = {
    14      init: function() {
    15          
    16      },
    17  
    18      testGetAccountState: function() {
    19          return Blockchain.getAccountState(Blockchain.transaction.from).balance;
    20      },
    21  
    22      testGetAccountStateWrongAddr: function() {
    23          return Blockchain.getAccountState("n1JNHZJEUvfBYfjDRD14Q73FX62nJAzXkMR").balance;
    24      },
    25  
    26      testGetAccountState1: function() {
    27          var from = Blockchain.transaction.from;
    28          var to = Blockchain.transaction.to;
    29          var value = new BigNumber(Blockchain.transaction.value);
    30  
    31          var fromState1 = Blockchain.getAccountState(from);
    32          // console.log("============", JSON.stringify(fromState1));
    33          var toState1 = Blockchain.getAccountState(to);
    34          // console.log(JSON.stringify(toState1));
    35  
    36          Blockchain.transfer(from, value);
    37          var fromState2 = Blockchain.getAccountState(from);
    38          // console.log(JSON.stringify(fromState2));
    39  
    40          var toState2 = Blockchain.getAccountState(to);
    41          // console.log(JSON.stringify(toState2));
    42          var fromBalance1 = new BigNumber(fromState1.balance);
    43          var fromBalance2 = new BigNumber(fromState2.balance);
    44          console.log(fromBalance1);
    45          console.log(fromBalance2);
    46          assert(fromBalance1.add(value).equals(fromBalance2), "err 1");
    47  
    48          var toBalance1 = new BigNumber(toState1.balance);
    49          var toBalance2 = new BigNumber(toState2.balance);
    50          assert(toBalance1.sub(value).equals(toBalance2), "err 2");
    51          assert(parseInt(toState1.nonce) == parseInt(toState2.nonce), "err3");
    52      },
    53  
    54      testGetAccountState2: function() {
    55          return Blockchain.getAccountState("0x1233455");
    56      },
    57  
    58      testGetPreBlockHash: function(offset) {
    59          var hash = Blockchain.getPreBlockHash(offset);
    60          var height = Blockchain.block.height;
    61          return {hash: hash, height: height};
    62      },
    63      testGetPreBlockHash1: function(offset) {
    64          return  Blockchain.getPreBlockHash(offset);
    65      },
    66  
    67      testGetPreBlockSeed: function(offset) {
    68          var seed = Blockchain.getPreBlockSeed(offset);
    69          var height = Blockchain.block.height;
    70          return {seed: seed, height: height};
    71      },
    72  
    73      testGetPreBlockSeed1: function(offset) {
    74          return Blockchain.getPreBlockSeed(offset);
    75      },
    76  
    77      testGetPreBlockHashByNativeBlock: function(offset) {
    78          return Blockchain.nativeBlockchain.getPreBlockHash(offset);
    79      },
    80  
    81      testGetPreBlockSeedByNativeBlock: function(offset) {
    82          return Blockchain.nativeBlockchain.getPreBlockSeed(offset);
    83      }
    84  
    85  }
    86  
    87  module.exports = testContract;