when need pass testConext to neovm contract, must write contract as def Main(operation, args) api. and args need be a list.
(testConext *TestContext)
| 126 | |
| 127 | // when need pass testConext to neovm contract, must write contract as def Main(operation, args) api. and args need be a list. |
| 128 | func buildTestConextForNeo(testConext *TestContext) []byte { |
| 129 | addrMap := testConext.AddrMap |
| 130 | builder := neovm.NewParamsBuilder(new(bytes.Buffer)) |
| 131 | |
| 132 | // [args, operation] |
| 133 | builder.Emit(neovm.SWAP) |
| 134 | // [operation, args] |
| 135 | builder.Emit(neovm.TOALTSTACK) |
| 136 | // [operation] |
| 137 | |
| 138 | // construct [admin, map] array |
| 139 | builder.EmitPushByteArray(testConext.Admin[:]) |
| 140 | builder.Emit(neovm.NEWMAP) |
| 141 | for file, addr := range addrMap { |
| 142 | builder.Emit(neovm.DUP) |
| 143 | builder.EmitPushByteArray(addr[:]) |
| 144 | builder.Emit(neovm.SWAP) |
| 145 | builder.EmitPushByteArray([]byte(file)) |
| 146 | builder.Emit(neovm.ROT) |
| 147 | builder.Emit(neovm.SETITEM) |
| 148 | } |
| 149 | builder.Emit(neovm.PUSH2) |
| 150 | builder.Emit(neovm.PACK) |
| 151 | // end [addmin, map] array construct |
| 152 | |
| 153 | // [operation, [admin, map]] |
| 154 | builder.Emit(neovm.FROMALTSTACK) |
| 155 | // [operation, [admin, map], args] |
| 156 | builder.Emit(neovm.UNPACK) |
| 157 | builder.Emit(neovm.PUSH1) |
| 158 | builder.Emit(neovm.ADD) |
| 159 | builder.Emit(neovm.PACK) |
| 160 | // [operation, [args,[admin, map]]] |
| 161 | builder.Emit(neovm.SWAP) |
| 162 | // the second list of last elt is the testConext |
| 163 | // [[args,[admin, map]], operation] ==> topof the stack. |
| 164 | return builder.ToArray() |
| 165 | } |
| 166 | |
| 167 | func GenNeoVMTransaction(testCase TestCase, contract common.Address, testConext *TestContext) (*types.Transaction, error) { |
| 168 | params, err := utils2.ParseParams(testCase.Param) |
no test coverage detected